杰克逊中不区分大小写的JsonNode [英] Case-insensitive JsonNode in Jackson

查看:157
本文介绍了杰克逊中不区分大小写的JsonNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要反序列化JSON对象并以不区分大小写的方式访问字段。示例:

I need to deserialize JSON objects and access the fields in a case-insensitive manner. Example:

String s = "{\"FOO\": 123}";
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(s);
node.get("foo"); // this should return the "FOO" field

这需要高效,所以调用 getFieldNames()并小写结果不是一个好的解决方案。

This needs to be performant, so calling getFieldNames() and lowercasing the results is not a good solution.

推荐答案

有没有自动化方式,但您可以通过创建自定义JsonNodeFactory来创建自定义ObjectNodes - 然后您可以覆盖用于添加和访问条目的方法。

There is no automated way, but you could do it by creating custom JsonNodeFactory which creates custom ObjectNodes -- and then you can override method(s) used for adding and accessing entries.

这篇关于杰克逊中不区分大小写的JsonNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆