I found it when I met this problem.
Springmvc @RequestBody problem: Unrecognized field, not marked as ignorable
This article says:
@JsonIgnoreProperties (Ignoreunknown = True), after the annotation is written on the class, fields that do not exist in the class are ignored, and the current needs are met. This annotation can also specify the fields to ignore. Here's how to use it:
@JsonIgnoreProperties ({"Internalid", "Secretkey"})
The specified field is not serialized and deserialized.
But my bean is similar to this:
public class p {private c c ;p ublic c getc () {return c;} Public void setc (C c) {this.c = c;} @Overridepublic string tostring () {return "p [c=" + c + "]";}} public class c {private string a;private string b;private string C;public string geta () {return a;} Public void seta (String a) {this.a = a;} PUBLIC STRING GETB () {return b;} PUBLIC VOID SETB (String b) {this.b = b;} PUBLIC STRING GETC () {return c;} Public void setc (String c) {this.c = c;} @Overridepublic string tostring () {return "c [a=" + a + ", b = " + b + ", c= " + c + "] ";}}
My JSON is like this:
{"C": {"a": "1", "B": "2", "C": "3", "D": "4"}}
I'm going to convert the P class, and the annotations are only valid if they're written to Class C. In practical applications, Class C is a public class provided by others and cannot be modified. So the annotation method fails.
So I found this article:
Jackson JSON conversion bean with no corresponding value in bean Jackson unrecognized field
But this is Jackson1, and I'm using the latest version of the 2, so it doesn't work according to his wording.
Find the information also did not find useful, and then try it yourself, after the 2.X version changed to this:
Mapper.setvisibility (Propertyaccessor.field, Visibility.any); Mapper.configure (Deserializationfeature.fail_on_ Unknown_properties, false);
This will solve the problem!
Jackson2 JSON conversion bean, no corresponding value in Bean Jackson UN solution