package com.qnfhq.common;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lombok.SneakyThrows;

import java.math.BigDecimal;

/**
 * 一句话描述
 *
 * @Author: Yelz 30262728@qq.com
 * @Date: 2025/11/24 14:21
 * @Description:
 */
public class BigDecimalSerialize extends JsonSerializer<BigDecimal> {
    @SneakyThrows
    @Override
    public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializerProvider) {
        if (value != null) {
            String plainStr = value.stripTrailingZeros().toPlainString();
            gen.writeString(plainStr);
        } else {
            gen.writeString(BigDecimal.ZERO.toPlainString());
        }
    }
}
