How do I resolve a key in JSON that requires an initial capitalization?

Source: Internet
Author: User

In general, we name all camel-like, but sometimes with the third-party interface, also encounter some wonderful things, such as the first letter capital .... Well, what the hell is this, the other side is so demanding, so we have to write it.

Thus, the first way: capitalize the first letter of the field in the class, simply brute, and then generate the setter getter. Then test ... Get on your knees.

Found or lowercase, the forehead drops a mother Ah, nen is what is the son ah.

It turns out that when Jackson turned the class into JSON, he looked at the setter getter method. That's JavaBean. Search Karma.

So, can we specify the field name of the JSON, like what's called in the class, and my JSON is called What the fuck

Yes, I can.

At this point, a self-explanatory note is needed: @JsonProperty

Everything is done, you can call whatever you want.

And to be on the safe side, it's best to add this annotation to each field, so that's the comment on the field?

No no No

We tested, the capital is no problem, but found that there will be more than a lowercase letter, well, it seems that the Getter played a role, simple

Let's just add the annotations to the setter and getter method.

Everything is done!!! It's so nice.



How do I resolve a key in JSON that requires an initial capitalization?

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.