org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field

使用Jackson 反序列化时,报错:

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "age" (Class com.common.bean.RequestInfoBean), not marked as ignorable
 at [Source: java.io.StringReader@32deb93a; line: 1, column: 151] (through reference chain: com.common.bean.RequestInfoBean["age"])

原因:

把json字符串jsonStr ,反序列化为RequestBean,当jsonStr 中的字段,java bean中没有时报错

解决方法:

mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

 

 

pom.xml:

<dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-lgpl</artifactId>
            <version>1.9.13</version>
        </dependency>

 参考:

http://blog.csdn.net/a9529lty/article/details/8232948

猜你喜欢

转载自hw1287789687.iteye.com/blog/2321476