Can someone help me to figure out what's need to be added?
JSON :
{"value":{"keyword":"better","correct":"","page":0,"size":10,"cost":51,"total":1107}}
Object class
@JsonAutoDetect
@JsonSerialize(include = Inclusion.NON_NULL)
@JsonRootName(value = "value")
public class Response {
private int page;
private int size;
private int total;
private int cost;
private int result;
private String keyword;
private String correct;
Still it gets the "Servlet.service() for servlet appServlet threw exception
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "value" (), not marked as ignorable"
Try adding this to your mapper config
mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
mapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
If you use RestTemplate you will need to configure the underlying jackson mapper. You can do this by configuring your mapper and setting it in the converter. See code below.
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
mapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
MappingJacksonHttpMessageConverter messageConverter = new MappingJacksonHttpMessageConverter();
messageConverter.setObjectMapper(mapper);
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(messageConverter);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setMessageConverters(messageConverters);
See here for more details: https://jira.springsource.org/browse/ANDROID-45
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With