A Java object converted to a JSON string is not able to get the corresponding field name

Source: Internet
Author: User

Problem:

The code has been labeled

@JSONField(name = "Attrs")

Private String ABC;

Public String Geta () {

Return ABC;

}

public void SetA (String ABC) {

THIS.ABC = ABC;

}

When sending a message, it is found that the JSON message received by the message is that the field of ABC corresponds to a.

Workaround:

When we find this problem, I think it should be the title of Get and set function name, change it to GETABC (), SETABC (), and send the message again, we will find that the corresponding field of ABC is attrs.

Reason:

Consult Daniel, look at the framework code, and do not see too clearly.

Presumably because the Java object is converted to a JSON string, there may be precedence, based on the name after the Get function, which is the example of a to match the member variable, if not found, the field name is a; If found, that is, if ABC, then can find, match on Attrs, The field name is Attrs.

A Java object converted to a JSON string is not able to get the corresponding field 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.