Server Response data:
{
"data": "{\"domain\":{\"Logical\":\"small_logical.png\",\"Physical\":\"small_physical.png\"}"
}
onFailure: Can not instantiate value of type [simple type, class com.mobile.app.model.Responses.Data] from String value ('{"domain":{"Logical":
Problem:
Inner json object starts with double quotes, so Jackson can't able to deserialize - "{\"domain\":
I tried with jackson deserialization, but nothing works with it
public class RestClient {
private static final String TAG = "RestClient";
private static RestApi REST_CLIENT;
public static RestApi get() {
return REST_CLIENT;
}
public static String RestApiUrl() {
return ROOT;
}
public static void setupRestClient() {
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addDeserializer(String.class, new ItemDeserializer());
objectMapper.registerModule(module);
Retrofit restAdapter = new Retrofit.Builder()
.baseUrl(RestApiUrl())
.client(client)
.client(getUnsafeOkHttpClient())
.addConverterFactory(JacksonConverterFactory.create(objectMapper)).build();
REST_CLIENT = restAdapter.create(RestApi.class);
}
}
public class ItemDeserializer extends StdDeserializer<String> {
private static final String TAG = "ItemDeserializer";
public ItemDeserializer() {
this(null);
}
public ItemDeserializer(Class<?> vc) {
super(vc);
}
@Override
public String deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
String jsonValue = jp.getValueAsString();
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(jsonValue);
} catch (JSONException e) {
e.printStackTrace();
}
Log.i(TAG, "deserializecustom: " + objectMapper.writeValueAsString(jsonObject));
return objectMapper.writeValueAsString(jsonObject);
}
}