Home Web Front-end JS Tutorial About how jackson parses json string

About how jackson parses json string

Jun 19, 2018 am 10:16 AM
jackson json string lower case Capitalize first letter

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},
Copy after login
Copy after login

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},
Copy after login
Copy after login

, 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 = "";
Copy after login

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;
 }
}
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Convert an array or object to a JSON string using PHP's json_encode() function Convert an array or object to a JSON string using PHP's json_encode() function Nov 03, 2023 pm 03:30 PM

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

Convert CSV to JSON using Jackson library in Java? Convert CSV to JSON using Jackson library in Java? Aug 18, 2023 pm 11:49 PM

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

Java program: Capitalize first letter of each word in a string Java program: Capitalize first letter of each word in a string Aug 20, 2023 pm 03:45 PM

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

How to convert JSON object to enum type in Java using Jackson? How to convert JSON object to enum type in Java using Jackson? Sep 05, 2023 pm 12:13 PM

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{&

How to solve the problem of specifying jackson version in SpringBoot upgrade How to solve the problem of specifying jackson version in SpringBoot upgrade May 12, 2023 pm 02:13 PM

[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

Convert XML to POJO using Jackson library in Java? Convert XML to POJO using Jackson library in Java? Aug 30, 2023 am 10:21 AM

TheJSONJacksonisalibraryforJava.IthasverypowerfuldatabindingcapabilitiesandprovidesaframeworktoserializecustomjavaobjectstoJSONanddeserializeJSONbacktoJavaobject.WecanalsoconvertanXMLformattothePOJOobjectusingthereadValue()methodoftheXmlMapper&nb

Convert POJO to XML using Jackson library in Java? Convert POJO to XML using Jackson library in Java? Sep 18, 2023 pm 02:21 PM

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

How to get JSONParser's default settings using Jackson in Java? How to get JSONParser's default settings using Jackson in Java? Sep 12, 2023 am 11:57 AM

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

See all articles