Java Jackson ignores non-existent attribute fields and goes to JSON by property name

Source: Internet
Author: User

Tag: class RET causes the BSP Sage case to exist annotated JSON

@JsonAutoDetect (fieldvisibility = visibility.any, gettervisibility = visibility.none, isgettervisibility = Visibility.none)
The purpose of this annotation is to use the property name to go to JSON. prevent irregular attribute errors, such as app_id

@JsonIgnoreProperties (Ignoreunknown = True)
The purpose of this annotation is that the JSON-to-object is to prevent an error from passing in a JSON string that contains a nonexistent property.


Case:


1@JsonAutoDetect (fieldvisibility = visibility.any, gettervisibility = visibility.none, isgettervisibility =Visibility.none)2@JsonIgnoreProperties (Ignoreunknown =true)3 Public classUnifiedpayorderresponse {4 5 PrivateString Code;6 7 PrivateString message;8 9 PrivateString Main_order_code;Ten One PrivateString app_id; A - PublicString GetCode () { - returnCode; the } - - Public voidSetcode (String code) { - This. Code =Code; + } - + PublicString getMessage () { A returnmessage; at } - - Public voidsetmessage (String message) { - This. Message =message; - } - in PublicString Getmain_order_code () { - returnMain_order_code; to } + - Public voidSetmain_order_code (String main_order_code) { the This. Main_order_code =Main_order_code; * } $ Panax Notoginseng PublicString getapp_id () { - returnapp_id; the } + A Public voidsetapp_id (String app_id) { the This. app_id =app_id; + } - $}

Java Jackson ignores non-existent attribute fields and goes to JSON by property name

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.