最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to use Jackson's JsonNodeFeature STRIP_TRAILING_BIGDECIMAL_ZEROES - Stack Overflow

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

ObjectMapper.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)

发布评论

评论列表(0)

  1. 暂无评论