English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Problem
The problem encountered by the owner is that a certain field named RMBPrice is defined in the entity class and table, with the first letter capitalized, and the column name RMBPrice queried by SQL is also uppercase. However, when initializing the column with jQuery datatables, an error occurs.
The code for that line is as follows:
{"name": "RMBPrice", "data": "RMBPrice", "className": "text-, "center", "render": formatRMBPrice},
However, when the page is opened, it will display this. Check the browser's call to the interface return value:
It is lowercase rmbprice
Analysis
The interface returns an @ResponseBody object, set a breakpoint in the code, and until the interface return value is all uppercase, so it is only possible that there was a problem during the conversion to JSON.
Baidu json, if the first letter is uppercase, an article about automatic conversion to lowercase appears.
After testing, it is indeed true that all the current uppercase letters will be converted to lowercase until they are not uppercase, and if there is an uppercase letter after lowercase, it will remain uppercase.
For example: RRRddRRR will become rrrddRRR.
Solution
I directly modify that line of code in js, changing it to:
{"name": "rmbprice", "data": "rmbprice", "className": "text-, "center", "render": formatRMBPrice},
After inquiry, if you want to retain uppercase, you need to add the annotation.
For example, Jackson usage:
When defining fields in entity classes:
@JsonProperty("ActionCode") private String ActionCode = "";
fastjson usage:
@JSONField(name = "Name") The 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; } }
There is also a saying that:
Forcibly convert, use com.alibaba.fastjson.serializer.PascalNameFilter to directly convert the first letter to uppercase. For example: JSON.toJSONString(bean, new PascalNameFilter());
However, I haven't tried any of the above because I have used the automatically converted lowercase name. If you want to keep the uppercase, you need to find more by yourself~~;9786;9786;
This is the whole content of the method of converting the first letter of the jackson parsed JSON string to lowercase automatically shared by the editor, hoping to provide a reference for everyone, and also hope that everyone will support and cheer for the tutorial.
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report via email to codebox.com (replace # with @ when sending an email) and provide relevant evidence. Once verified, this site will immediately delete the infringing content.