I have BigDecimalSerializer
public class BigDecimalSerializer extends JsonSerializer<BigDecimal> {
@Override
public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
gen.writeString(value.setScale(6, BigDecimal.ROUND_HALF_UP).toString());
}
}
and then
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal foo;
is there any way that instead of doing annotate in each member variable, I tell the spring boot at once that apply to all project ?
Try configuring the
ObjectMapperby adding a custom module. In case you're usingspring-data-restthis can look like this:Otherwise simply provide your own
ObjectMapperbean and configure it on creation.