This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18884|Reply: 1

[Source] Fastjson JSONField deserialization invalid solution

[Copy link]
Posted on 1/11/2019 10:51:31 AM | | | |
I used Alibaba's Fastjson to serialize and deserialize objects, because my original json strings were all a, b, c... Such letters are represented, but I serialize them into objects, and I can't define objects as such meaningless properties.
JSONField annotations are used here.

@JSONField the difference between putting on a field and the get set method

  • field, specifying both serialization and deserialization operations
  • Put on get, specifying the operation when serializing
  • set, specifies the operation when deserializing



After I use it, it can be serialized normally, but it cannot be deserialized normally, as shown in the figure below:


json string:

{"a":"shenzhou","b":"Jing Q7UB02","c":110000,"d":"2019-01-08T17:07:04+08:00","e":120.775085,"f":30.13825,"g":77,"h":171,"i":0,"j":4951,"k":2,"l":0,"m":0,"n":4,"o":"0","p" :1}


Error causes:

The properties of objects do not follow Java's hump nomenclature, with all but the first word capitalized. For example

int myStudentCount;
The variable myStudentCount is all lowercase, and the first letter of the word after it is capitalized.

Solution:

Modify the name of the object attribute and regenerate the get/set method with the following code:

For the correct attributes, deserialization succeeds, as shown in the following image:







Previous:Workplace e-books
Next:The PFD format is also mixed with some other books
 Landlord| Posted on 1/14/2019 4:29:58 PM |
I have given up fastjson and switched to Jackson, and I encountered Alibaba's open source.
Here's how to use it:

pop.xml



JAVA Object to JSON [JSON Serialization]



JSON to Java Classes [JSON deserialization]



Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com