JsonNode findValue不搜索子节点 [英] JsonNode findValue Without Searching Child Nodes

查看:613
本文介绍了JsonNode findValue不搜索子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的资源结构如下:

"activity": {
            "activity_type": "Like",
            "activity_id": "123456",
            "object_id": "",
            "product_id":"",
            "reference_activity": {
                    "activity_type": "Rating",
                    "activity_id": "789456",
                    "object_id": "rating/5",
                    "product_id": "product.v1.13445123",
                    "timestamp": 1433447044000
            },
            "timestamp": 1435790640115
}

问题是资源可以包含同一类的对象(即引用另一个活动)。因此,它们具有相似的值名称。我正在尝试使用Jackson的JsonNode.findValue()方法解析此JSON结构,但findValue()方法也执行嵌套搜索。因此,如果我执行findValue(object_id),它将永远不会返回空字符串。相反,它将始终返回rating / 5。

The problem is that the resource can contain an object of the same class (i.e. referencing another "activity"). As a result, they have similar value names. I'm trying to parse this JSON structure using Jackson's JsonNode.findValue() method, but the findValue() method does a nested search as well. So if I do a findValue("object_id"), it will never return the empty string. Instead, it will always return "rating/5".


  1. 有没有办法将findValue()方法限制为直接的
    子项?

  2. 或者,有没有办法从
    父结构中删除reference_activity对象(但仍保留JsonNode对象),以便我可以单独解析它们?


推荐答案

如果您不需要递归查找,只需使用路径获取方法?

If you don't need recursive find, just use path or get methods?

这篇关于JsonNode findValue不搜索子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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