package vip.xiaonuo.coldchain.modular.app.param;

/**
 * @author jackzhou
 * @version 1.0
 * @project jfcloud-coldchain
 * @description
 * @date 2024/11/23 19:01:49
 */

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

import java.io.IOException;

public class FloatCo2ToDashSerializer extends JsonSerializer<Float> {
    @Override
    public void serialize(Float value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value == null) {
            gen.writeString("-");  // 如果值为 null，返回 "-"
        } else {
            // 四舍五入到整数
            int roundedValue = Math.round(value);  // 四舍五入为整数
            gen.writeNumber(roundedValue);  // 输出整数值
        }
    }
}
