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

About how jackson parses json string

亚连
Release: 2018-06-19 10:16:28
Original
3089 people have browsed it

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

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

, 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!

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template