com.cloud.platform.common.serializer.LongToStringSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
project for platform-common
The newest version!
package com.cloud.platform.common.serializer;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
/**
* @description: 防止雪花算法导致的精度丢失
* @author: zhou shuai
* @date: 2022/4/4 13:29
* @version: v1
*/
public class LongToStringSerializer extends JsonSerializer {
@Override
public void serialize(Long aLong, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
String str = String.valueOf(aLong);
if (str.length() >= 18) {
jsonGenerator.writeString(str);
} else {
jsonGenerator.writeNumber(aLong);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy