I'm trying to parse JSON so that the trailing zeros are preserved. How do I do this with Jackson?
I have Jackson version 2.18.0
This is what I'm trying to do now:
ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec();
mapper.configure(JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES, false);
JsonNode root = mapper.readTree(jsonParser);
But that doesn't work. All zeros are still being removed.
I'm trying to parse JSON so that the trailing zeros are preserved. How do I do this with Jackson?
I have Jackson version 2.18.0
This is what I'm trying to do now:
ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec();
mapper.configure(JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES, false);
JsonNode root = mapper.readTree(jsonParser);
But that doesn't work. All zeros are still being removed.
Share Improve this question asked Feb 3 at 10:27 eeropueeropu 1 1- Could it be that you're trying to configure the mapper after it's already been used? If so, the documentation says it's unsafe and that you should not do that. – k314159 Commented Feb 3 at 12:13
1 Answer
Reset to default 0ObjectMapper.configure(...)
returns a new instance rather than mutating the existing instance. I believe you'd do something like
ObjectMapper mapper1 = (ObjectMapper) jsonParser.getCodec();
ObjectMapper mapper2 = mapper1.configure(JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES, false);
JsonNode root = mapper2.readTree(jsonParser);
Note also that mapper.configure(x, false)
and be simplified as mapper.disable(x)