net.guerlab.spring.commons.jackson.serializer.NumberStringSerializer Maven / Gradle / Ivy
package net.guerlab.spring.commons.jackson.serializer;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* 数值类型字符串序列化
*
* @author guer
*
*/
public class NumberStringSerializer extends JsonSerializer {
@Override
public void serialize(Number value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value == null) {
gen.writeNull();
return;
}
gen.writeString(value.toString());
}
}