Jackson2 JSON conversion bean, no corresponding value in Bean Jackson UN solution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.