I need download json object from REST server without converting by GSON. But not understand how make in Retrofit 2.0 bata 1
相关问题
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Bottom Navigation View gets Shrink Down
Simply use
JsonElement
as your pojo. For exampleIn your FlowerApi interafce:
In your main class:
Actually, the response is still converted to
JsonElement
by the Gson converter, but you can get something that is close to the raw response.We can get JsonObject (com.google.gson) and parse this as well as standard JSONObject (org.json)
Interface FlowerApi
In rest handler use
Api Factory class help a create retrofit service easy
In build.gradle
1
compile 'io.reactivex:rxjava:1.0.+' compile 'com.squareup.retrofit:retrofit:2.0.0-beta1' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1' compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1' compile 'com.squareup.okhttp:okhttp:2.5.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
2
OkHttpClient client = new OkHttpClient(); // client.interceptors().add(new UrlInterceptor()); client.interceptors().add(new LoggingInterceptor()); AppApi api = new Retrofit.Builder() .baseUrl("https://api.github.com") // add a converter for String .addConverter(String.class, new ToStringConverter()) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .client(client) .build() .create(AppApi.class);