About how jackson parses json string
Below I will share with you a method of Jackson parsing json strings. The first capital letter will be automatically converted to lower case. It has a good reference value and I hope it will be helpful to everyone.
Problem
The problem the poster encountered is that a certain field defined in the entity class and table is RMBPrice, with the first letter capitalized. The column name queried by sql is also RMBPrice in uppercase, but when using jquery's datatables to initialize the column, an error occurs.
The code for that line is as follows:
{"name": "RMBPrice", "data": "RMBPrice", "className": "text-center", "render": formatRMBPrice},
This will be displayed when opening the page. Check the value returned by the browser calling interface:
is lowercase rmbprice
Analysis
The interface returns a @ResponseBody object. From the break point in the code, the return value of the interface is all in uppercase, so it can only happen when converting to json. question.
If the first letter of Baidu json is capitalized, articles will be automatically converted to lowercase.
After testing, it is true that the current few letters that are all uppercase will be converted to lowercase until they are no longer uppercase. If there is an uppercase after the lowercase, it will remain in uppercase.
For example: RRRddRRR will become rrrddRRR.
Solution
I directly modify the line of code in js and change After querying:
{"name": "RMBPrice", "data": "RMBPrice", "className": "text-center", "render": formatRMBPrice},
, if you want to retain uppercase, you need to add annotations.
For example, jackson uses:
When defining fields in entity classes:
@JsonProperty("ActionCode") private String ActionCode = "";
fastjson uses:
@JSONField(name = “Name”) And this tag should be marked before the get method:
public class User { private String name; private int age; @JSONField(name = "Name") public String getName(){ return name; } public void setName(String name){ this.name = name; } @JSONField(name = "Age") public int getAge(){ return age; } public void setAge(int age){ this.age= age; } }
Also said:
Force conversion , use com.alibaba.fastjson.serializer.PascalNameFilter to directly convert the first letter to uppercase. For example: JSON.toJSONString(bean,new PascalNameFilter());
However, I have not tried the above because I used the name after automatic conversion to lowercase. If you want to keep the capitalization, you need to search more by yourself~~☺☺
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to achieve the display box effect in the Vue component Toast
About rules parameter processing in webpack
How to implement simple calculations in AngularJS
Solution to the Bootstrap modal box submission bug
Detailed interpretation of the entry function run in webpack
How to implement entry/leave animation in Vue
About routing in node.js, the middle Detailed description of the file
The above is the detailed content of About how jackson parses json string. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JSON (JavaScriptObjectNotation) is a lightweight data exchange format that has become a common format for data exchange between web applications. PHP's json_encode() function can convert an array or object into a JSON string. This article will introduce how to use PHP's json_encode() function, including syntax, parameters, return values, and specific examples. Syntax The syntax of the json_encode() function is as follows: st

AJackson is a Java JSON API that provides several different ways to process JSON. We can convert CSV data to JSON data using the CsvMapper class, which is a special ObjectMapper with extended functionality to convert POJOs into CsvSchema instances. We can build an ObjectReader with default settings using the reader() method. In order to convert we need to import com.fasterxml.jac

Astringisaclassof'java.lang'packagethatstoresaseriesofcharacters.ThosecharactersareactuallyString-typeobjects.Wemustenclosethevalueofstringwithindoublequotes.Generally,wecanrepresentcharactersinlowercaseanduppercaseinJava.And,itisalsopossibletoconver

JSONObject can parse text in a string to generate a Map type object. Enumerations can be used to define collections of constants, and we can use enumerations when we need a predefined list of values that does not represent some kind of numeric or textual data. We can convert JSON objects into enumerations using the readValue() method of the ObjectMapper class. In the example below, we can use the Jackson library to convert/deserialize a JSON object into a Java enumeration. Example importcom.fasterxml.jackson.databind.*;publicclassJSONToEnumTest{&

[Vulnerability Notice] On February 19, NVD issued a security notice disclosing a remote code execution vulnerability (CVE-2020-8840) in jackson-databind caused by JNDI injection, with a CVSS score of 9.8. The affected version of jackson-databind lacks certain xbean-reflect/JNDI blacklist classes, such as org.apache.xbean.propertyeditor.JndiConverter, which can lead to attackers using JNDI injection to achieve remote code execution. At present, the manufacturer has released a new version to complete the vulnerability repair. Relevant users are requested to upgrade in time for protection. Since the S used in the project

TheJSONJacksonisalibraryforJava.IthasverypowerfuldatabindingcapabilitiesandprovidesaframeworktoserializecustomjavaobjectstoJSONanddeserializeJSONbacktoJavaobject.WecanalsoconvertanXMLformattothePOJOobjectusingthereadValue()methodoftheXmlMapper&nb

Jackson is a Java-based library that is useful for converting Java objects to JSON and JSON to Java objects. JacksonAPI is faster than other APIs, requires less memory area, and is suitable for large objects. We use the writeValueAsString() method of the XmlMapper class to convert the POJO to XML format, and the corresponding POJO instance needs to be passed as a parameter to this method. Syntax publicStringwriteValueAsString(Objectvalue)throwsJsonProcessingExceptionExampleimp

The default settings for all JSON parsers can be represented using the JsonParser.Feature enumeration. JsonParser.Feature.values() will return all features available for JSONParser, but whether a feature is enabled or disabled for a specific parser can be determined using JsonParser's isEnabled() method. Syntax publicstaticenumJsonParser.FeatureextendsEnum<JsonParser.Feature>Example importcom.fas
