jackson反序列化时忽略不需要的字段(zhuan)

http://www.cnblogs.com/davidwang456/p/5434071.html

*********************************************

有时候,如果数据库表中增加一个字段,但返回的JSON字符串中含有我们并不需要的字段,那么当对应的实体类中不含有该字段时,会抛出一个异常,告诉你有些字段没有在实体类中找到。解决办法很简单,在声明ObjectMapper之后,加上上述代码:

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

     java.lang.Object
        java.lang.Enum<DeserializationFeature>
            com.fasterxml.jackson.databind.DeserializationFeature

FAIL_ON_UNKNOWN_PROPERTIES

Feature that determines whether encountering of unknown properties (ones that do not map to a property, and there is no "any setter" or handler that can handle it) should result in a failure (by throwing a JsonMappingException) or not.
 
原文地址:https://www.cnblogs.com/zhao1949/p/6149993.html