简体   繁体   English

JSON:无法识别的字段“值”( <objectClass> ),没有标记为可忽略的

[英]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.

相关问题 JSON 到 Java 对象 - 无法识别的字段,未标记为可忽略 - JSON to Java object - Unrecognized field, not marked as ignorable 未被识别的字段,未标记为可忽略 - unrecognized field, not marked as ignorable Jackson Json 反序列化:无法识别的字段“...”,未标记为可忽略 - Jackson Json Deserialisation: Unrecognized field “…” , not marked as ignorable Jackson 与 JSON:无法识别的字段,未标记为可忽略 - Jackson with JSON: Unrecognized field, not marked as ignorable 无法识别的字段类未标记为可忽略 - Unrecognized field class not marked as ignorable 将 JSON 映射到 POJO 进行处理 - 无法识别的字段未标记为可忽略 - Map JSON to POJO For Processing - Unrecognized field not marked as ignorable 解析json字符串时,无法识别的字段(未标记为可忽略) - Unrecognized field , not marked as ignorable ,when parsing json string Spring Jackson-无法识别的字段“ response”在以下位置未标记为可忽略 - Spring Jackson - Unrecognized field \“response\” not marked as ignorable at jackson java无法识别的字段未标记为可忽略 - jackson java Unrecognized field not marked as ignorable 如何使用 Spring 将 JSON 数据插入 H2 数据库中的错误“无法识别的字段“名称,未标记为可忽略”? - How to get around error “Unrecognized field ”Name, not marked as ignorable", to insert JSON data into H2 database with Spring?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM