前言

Github:https://github.com/HealerJean

博客:http://blog.healerjean.com

1、序列化

public class DecimalSerialize extends JsonSerializer<BigDecimal> {


    @Override
    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String value = null;
        if(bigDecimal != null) {
            BigDecimal b = bigDecimal.setScale(0);
            value = b.toString();
        }
        jsonGenerator.writeString(value);
    }
}

2、反序列化

public class DecimalSerialize extends JsonSerializer<BigDecimal> {


    @Override
    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String value = null;
        if(bigDecimal != null) {
            BigDecimal b = bigDecimal.setScale(0);
            value = b.toString();
        }
        jsonGenerator.writeString(value);
    }
}

3、使用

@JsonSerialize(using = UserBelongSerialize.class)
@JsonDeserialize(using = DecimalSerialize.class)

ContactAuthor