Java – how to find the parent JSON node when parsing JSON

I'm using Jackson to parse JSON streams

The API I'm using is objectmapper readTree(..)

Consider the following flows:

{
  "type": "array","items": {
      "id": "http://example.com/item-schema","type": "object","additionalProperties": {"$ref": "#"}
  }
}

Now when I read the additionalproperties, I find that a "$ref" is defined here Now to resolve the reference, I need to go to its parent node and find the ID (resolution infrastructure)

I can't find any API to go to the parent of jsonnode holding additionalproperties Is there any way to achieve this goal?

Information:

Why I need this is that I need to find the basic pattern that must parse $Ref To figure out the infrastructure, I need to know the ID of its parent

Solution

The Jackson JSON tree is single linked and has no parent link This helps to reduce memory usage (because many leaf nodes can be shared) and has the disadvantage that the construction efficiency is slightly higher, but it can not move up and down in the hierarchy

Therefore, you need to track yourself or use your own tree model

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>