Jackson < version 2.19
Did NOT work: JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN and SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN.
Below fix works:
ObjectMapper objectMapper = new ObjectMapper();
JsonNodeFactory customJsonNodeFactory = new JsonNodeFactory(true);
objectMapper.setNodeFactory(customJsonNodeFactory);
JsonNodeFactory has a constructor which sets the property big decimal exact.
public JsonNodeFactory(boolean bigDecimalExact)
{
_cfgBigDecimalExact = bigDecimalExact;
}
Reason : Because if this _cfgBigDecimalExact property is false, then it calls BigDecimal.stripTrailingZeros() which converts it to exponent form, hence setting it to true solves our issue.
Jackson > version 2.19
A property was introduced STRIP_TRAILING_BIGDECIMAL_ZEROES. Setting this as false skips BigDecimal.stripTrailingZeros() call.