package com.crunii.micro.common.serializer;

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

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

public class PercentSerializer extends JsonSerializer<BigDecimal> {
 
    public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value != null) {
            DecimalFormat decimalFormat2 = new DecimalFormat("0.######%");
            String format = decimalFormat2.format(value);
            gen.writeString(format);
        } else {
            gen.writeNumber(value);
        }
 
    }
}
