아.. retrofit 2.0은 정보가 많이 없구나...
xml 이 제대로 된 형태가 아니라서 어쩔수 없이 일부 모델에 대해선 직접 파싱을 해야해서 어케어케 해보니 아래와 같이 하면 되더이다..
맞는 방법인지는 몰겠음 -_-;;
Retrofit.Builder builder = new Retrofit.Builder();
builder.baseUrl(baseUrl);
builder.addConverterFactory(new ConverterFactory());
public static class ConverterFactory extends Converter.Factory {
SimpleXmlConverterFactory defaultConverter;
public ConverterFactory() {
defaultConverter = SimpleXmlConverterFactory.create();
}
@Override
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
return defaultConverter.toRequestBody(type, annotations);
}
@Override
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
if (!(type instanceof Class)) {
return null;
}
Class<?> cls = (Class<?>) type;
if (cls == MyModel.class) {
return new MyModel.MyModelConverter();
}
return defaultConverter.fromResponseBody(type, annotations);
}
}
public class MyModel{
// has members..
public static class MyModelConverter implements Converter<ResponseBody, MyModel> {
@Override
public MenuList convert(ResponseBody value) throws IOException {
MyModel model = new MyModel();InputStream is = value.byteStream();
try {
InputNode read = NodeBuilder.read(is);// make model...
} catch (Exception e) {
e.printStackTrace();
} finally {
is.close();
}
return model ;
}
}
}
'지식쌓기 > 개발-Android' 카테고리의 다른 글
| [Android] 디버깅시 Native 에서 죽을때 (Fatal signal 6 (SIGABRT)) (0) | 2018.08.20 |
|---|---|
| ffmpeg - android 용 빌드 하기 (0) | 2016.12.06 |
| 안드로이드 앱) allklips 소개 ㅋ (0) | 2014.10.12 |
| Android - adb start activity (0) | 2014.07.16 |
| Android - Google login / Google plus login 뭐가 다르냐!!! (1) | 2014.06.17 |