Currently, I\'m using Jackson to send out JSON results from my Spring-based web application.
The problem I\'m having is trying to get all money fields to output with
Inspired by Steve, and as the updates for Java 11. Here's how we did the BigDecimal reformatting to avoid scientific notation.
public class PriceSerializer extends JsonSerializer {
@Override
public void serialize(BigDecimal value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
// Using writNumber and removing toString make sure the output is number but not String.
jgen.writeNumber(value.setScale(2, RoundingMode.HALF_UP));
}
}