Use Jackson to parse the first uppercase JSON string

Source: Internet
Author: User

Jackson always had an error parsing the returned JSON string, and it was a long time before the reason was found because the letters in the JSON string were capitalized, causing Jackson to not find the key.


The data obtained from the server is often used in the project, and sometimes the first letter in the JSON string obtained from the server is capitalized, and the use of Jackson parsing is to report the error:

Exception in thread "main" org.codehaus.jackson.map.exc.UnrecognizedPropertyException:Unrecognized Field "XXX" (Class xxxx), not marked as ignorable.

The exception information tells that the XXX attribute field is not found in type XXX and is not marked as ignored.

But this field does exist in your bean, except that the first letter of the field is capitalized.

To solve this problem, you only need to add @jsonproperty () to the attribute field.

1  Public classCommissionitemvoImplementsserializable{2 3     /**4      * 5      */6     Private Static Final LongSerialversionuid = 1L;7     8     Private intdocId;9@JsonProperty ("CName")Ten     PrivateString CName; One@JsonProperty ("Cphone") A     PrivateString Cphone; -@JsonProperty ("Blockname") -     PrivateString Blockname; the@JsonProperty ("Seetime") -     PrivateString seetime; -@JsonProperty ("Cost") -     PrivateString cost; +@JsonProperty ("Endsettletime") -     PrivateString endsettletime; +      A      Public intgetdocid () { at         returndocId; -     } -  -  -  -      Public voidSetdocid (intdocId) { in          This. DocId =docId; -     } to  +  -  the      PublicString Getcname () { *         returnCName; $     }Panax Notoginseng  -  the  +      Public voidsetcname (String cName) { ACName =CName; the     } +  -  $  $      PublicString Getcphone () { -         returnCphone; -     } the  - Wuyi  the      Public voidSetcphone (String cphone) { -Cphone =Cphone; Wu     } -  About  $  -      PublicString Getblockname () { -         returnBlockname; -     } A  +  the  -      Public voidsetblockname (String blockname) { $Blockname =Blockname; the     } the  the  the  -      PublicString Getseetime () { in         returnSeetime; the     } the  About  the  the      Public voidsetseetime (String seetime) { theSeetime =Seetime; +     } -  the Bayi  the      PublicString Getcost () { the         returnCost ; -     } -  the  the  the      Public voidsetcost (String cost) { theCost =Cost ; -     } the  the  the 94      PublicString Getendsettletime () { the         returnEndsettletime; the     } the 98  About  -      Public voidsetendsettletime (String endsettletime) {101Endsettletime =Endsettletime;102     }103 104  the 106      Public Static LongGetserialversionuid () {107         returnSerialversionuid;108     }109  the 111  the @Override113      PublicString toString () { the         return"Commissionitemvo [docid=" + DocId + ", cname=" + CName + ", cphone=" + Cphone + ", blockname=" + Blockname + ", seetime=" + Seetime + ", cost=" + Cost + ", endsettletime=" + Endsettletime + "]"; the     } the     117     118     119}

Use Jackson to parse the first uppercase JSON string

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.