Java解决转换json时精度丢失问题

package com.jeesite.modules.common.json;

import java.io.IOException;
import java.math.BigDecimal;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class BigDecimalStringJsonSerialize extends JsonSerializer<BigDecimal> {
    
    @Override
    public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value != null) {
            gen.writeString(value.toString());
        } else {
            gen.writeString("");
        }
    }


}
@JsonProperty("this_month_happen")
    @JsonSerialize(using = BigDecimalStringJsonSerialize.class)
    public BigDecimal getThisMonthHappen() {
        return thisMonthHappen;
    }

 

posted on 2021-01-11 16:14  -韩帅  阅读(1213)  评论(0编辑  收藏  举报

导航