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:
|