The back end transmits long data to the front end, which can cause loss of precision. For example:201511200001725439 Such a long integer, passed to the front end will become 201511200001725440.
Workaround:
Method One: In the background to convert the long field to string type, the risk is relatively large.
Method Two: Use the provided annotations of Fastjson,@JSONField (serializeusing= tostringserializer.class).
Note:
Fastjson provides a variety of annotation for data type conversions under the Com.alibaba.fastjson.serializer package.
You can also expand these annotations by implementing the Objectserializer interface.
Tostringserializer 's code:
Public classTostringserializerImplementsObjectserializer { Public Static FinalTostringserializer instance =NewTostringserializer (); @Override Public voidWrite (Jsonserializer Serializer, Object object, Object FieldName, Type FieldType,intFeaturesthrowsIOException {serializewriter out=serializer.out; if(Object = =NULL) {out.writenull (); return; } String strval=object.tostring (); Out.writestring (Strval); }}
Converting a long type to a string type by Fastjson