Jackson 从根数组中获取密钥的值
我需要快速解析出类似 JSON 的根节点,如下所示:
[
{"key":"foo", "value":123},
{"key":"bar", "value":"Hello World!"},
{"key":"far", "value":{"something":1}}
]
简单地说,我需要查看“key”的值(即“foo”、“bar”、“far”),以确定是否需要将“值”部分完全反序列化为 POJO。
我尝试过为 POJO 映射创建一个类,但这会带来很大的开销,而且它特别不喜欢 Map,因为我的值的内部有时是值类型,有时更多是 JSON。
有什么想法可以快速遍历键,然后取出值并反序列化它吗?
提前致谢!
I need to quickly parse out the root node of similar JSON like below:
[
{"key":"foo", "value":123},
{"key":"bar", "value":"Hello World!"},
{"key":"far", "value":{"something":1}}
]
Simply put, I need to look at the "key"'s value (i.e. "foo", "bar", "far"), to determine if I need to fully deserialize the "value" portion to POJOs.
I have tried creating a class for POJO mapping, but that has a lot of overhead and it especially doesn't like a Map because the inside of my value is sometimes a value-type and sometimes more JSON.
Any ideas how I can traverse the keys quickly and then take the value out and deserialize it?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想绑定为树(ObjectMapper.readTree(),给出根节点的 JsonNode),遍历,然后使用 ObjectMapper.readValue(valueNode) 单独反序列化值?
You might want to bind as a tree (ObjectMapper.readTree(), gives JsonNode of root node), traverse, and then deserialize values separately, using ObjectMapper.readValue(valueNode)?