This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| retrofit [2017/06/16 17:10] – ledyx | retrofit [2021/02/07 05:49] (current) – old revision restored (2017/06/22 14:06) ledyx | ||
|---|---|---|---|
| Line 50: | Line 50: | ||
| T service = (T) services.get(restfulInterface.getName()); | T service = (T) services.get(restfulInterface.getName()); | ||
| - | if(service == null) { | + | if(service == null) { |
| - | | + | |
| - | String url = (String) f.get(null); | + | throw new Exception("Must be annotated |
| + | |||
| + | URL urlAnnotation = restfulInterface.getDeclaredAnnotation(URL.class); | ||
| + | |||
| + | String url = urlAnnotation.value(); | ||
| + | if(url.length() <= 0 || !url.substring(0, | ||
| + | throw new Exception(" | ||
| + | |||
| + | boolean isUnwrapRootValue = urlAnnotation.isUnwrappedRoot(); | ||
| HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); | HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); | ||
| Line 72: | Line 80: | ||
| .client(client) | .client(client) | ||
| .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
| - | .addConverterFactory(JacksonConverterFactory.create()) | + | .addConverterFactory(getConverterFactory(isUnwrapRootValue)) |
| .build().create(restfulInterface); | .build().create(restfulInterface); | ||
| Line 81: | Line 89: | ||
| } | } | ||
| + | private static JacksonConverterFactory getConverterFactory(boolean isUnwrapRootValue) { | ||
| + | ObjectMapper objectMapper = new ObjectMapper(); | ||
| + | objectMapper.registerModule(new JodaModule()); | ||
| + | objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); | ||
| + | objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | ||
| + | if(isUnwrapRootValue) | ||
| + | objectMapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); | ||
| + | | ||
| + | return JacksonConverterFactory.create(objectMapper); | ||
| + | } | ||
| + | | ||
| /** | /** | ||
| * 인증서 무시 | * 인증서 무시 | ||
| Line 107: | Line 126: | ||
| <sxh java ; title: | <sxh java ; title: | ||
| + | @URL(value = " | ||
| public interface DemoService { | public interface DemoService { | ||
| - | |||
| - | String URL = " | ||
| - | |||
| @GET(" | @GET(" | ||
| Observable< | Observable< | ||
| Line 123: | Line 140: | ||
| @DELETE(" | @DELETE(" | ||
| Observable< | Observable< | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <sxh java ; title: | ||
| + | @Target(ElementType.TYPE) | ||
| + | @Retention(RetentionPolicy.RUNTIME) | ||
| + | public @interface URL { | ||
| + | String value() default ""; | ||
| + | boolean isUnwrappedRoot() default false; | ||
| } | } | ||
| </ | </ | ||