@JsonSerialize(using = BigDecimalSerializer.class)
public class BigDecimalSerializer extends JsonSerializer
@Override
public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
BigDecimal _value = value;
if (value == null) {
_value = new BigDecimal(0);
}
NumberFormat numberFormat = NumberFormat.getNumberInstance();
numberFormat.setMaximumFractionDigits(8);
numberFormat.setMinimumFractionDigits(_value.scale());
numberFormat.setGroupingUsed(false);
numberFormat.setRoundingMode(RoundingMode.FLOOR);
gen.writeString(numberFormat.format(_value));
}
}
标签:BigDecimal,numberFormat,value,class,BigDecimalSerializer,public From: https://www.cnblogs.com/youkiko/p/18050839