Fastjson output value First letter case problem

Source: Internet
Author: User

Solution:

1. If your project is a multi-module and distributed deployment, consider using the setup System.property

2. Generally only a very small number of code this situation, it is recommended that directly in your singleton service initialization, in the static block directly change the value of the typeutils variable, if you use spring can be used Initializingbean processing

Typeutils.compatiblewithjavabean = true;

3. This variable is public note to make changes in one place to avoid thread safety issues

The project group uses Fastjson, which occurs when the following JSON is output, expecting it to be uppercase but Fastjson to turn the value auto-first letter to lowercase

{"Code": 0, "message": "", "result": {"facts": {"IP": {"acun_one_min": 0, "Acun_ten_min": 0}}, "Level": 0}}

after the query found Fastjson internal bean conversion will be used to com.alibaba.fastjson.util.TypeUtils, the core code as follows, when the class is loaded to read the environment variables Fastjson.compatiblewithjavabean, if not found, the default value of FALSE will cause the first letter lowercase

 Public Static BooleanCompatiblewithjavabean =false; Static {        Try{String prop= System.getproperty ("Fastjson.compatiblewithjavabean"); if("True". Equals (prop)) {Compatiblewithjavabean=true; } Else if("false". Equals (prop)) {Compatiblewithjavabean=false; }        } Catch(Throwable ex) {//Skip}    }

public static list<fieldinfo> Computegetters (class<?> clazz, map<string, String> AliasMap, Boolean Sorted) {

String PropertyName;
if (Character.isuppercase (C3)) {
if (compatiblewithjavabean) {
PropertyName = Introspector.decapitalize (methodname.substring (3));
} else {
PropertyName = Character.tolowercase (Methodname.charat (3)) + methodname.substring (4);
}
} else if (C3 = = ' _ ') {
PropertyName = Methodname.substring (4);
} else if (C3 = = ' F ') {
PropertyName = Methodname.substring (3);
} else {
Continue
}}

Fastjson output value First letter case problem

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.