I am parsing a JSON Stream using Jackson.
API that I am using is ObjectMapper.readTree(..)
Consider following stream:
{
"type": "array",
"items": {
"id": "http://example.com/item-schema",
"type": "object",
"additionalProperties": {"$ref": "#"}
}
}
Now when I read additionalProperties, I figure out there is a "$ref" defined here. Now to resolve the reference, I need to go to its parent and figure out the id (to resolve the base schema).
I can't find any API to go to parent of JsonNode holding additionalProperties. Is there a way I can achieve this?
Info:
Why I need this is I need to find the base schema against which $ref has to be resolved. And to figure out base schema, I need to know the id of its parents..
Got it!
Jackson JSON Trees are singly-linked, there is no parent linkage. This has the benefit of reduced memory usage (since many leaf-level nodes can be shared) and slightly more efficient building, but downside of not being able to traverse up and down the hierarchy.
So you will need to keep track of that yourself, or use your own tree model.
I am not able to understand the exact context of your problem. But I was doing some similar thing where I had to find a property value and then change it if the value meets some sort of criteria.
To search the value node I used
at
function withJsonPointer
and to go to Parent I usedJsonPointer.head
function and usedat
again on root json node.example as below