[英]JSON : Unrecognized field “value” (<objectClass>), not marked as ignorable
Can someone help me to figure out what's need to be added? 有人可以帮我弄清楚需要添加什么吗?
JSON : 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 它仍然得到servlet appServlet的“Servlet.service()引发异常
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "value" (), not marked as ignorable"
org.codehaus.jackson.map.exc.UnrecognizedPropertyException:无法识别的字段“value”(),未标记为可忽略“
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. 如果使用RestTemplate,则需要配置底层的jackson映射器。 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 有关详细信息,请参见此处: https : //jira.springsource.org/browse/ANDROID-45
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.