Closed JorgeCepeda closed 1 year ago
This would definitely need actual description of what is desired: title is quite ambiguous.
I updated the description with an example of what I'm trying to do, I see for Json one option is JsonPath
https://github.com/json-path/JsonPath https://www.w3schools.com/xml/xpath_syntax.asp
Maybe https://cassiomolin.com/2016/07/13/using-jackson-and-json-pointer-to-query-and-parse-an-arbitrary-json-node/ is worth a read. If you Google Jackson and JSON pointer or Path, you will find lots of existing solutions.
I'm able to read json, but I need to keep the node since the structure is arbitrary
My main issue is that XPath is strongly XML-specific, ditto for attributes. It will not be usable for things other than XML, since concept of attributes (f.ex) are XML-isms. As such I do not think JSON Pointer should have anything special beyond its (simple) specification.
But it does sound like this would be specific for Jackson XML format module (jackson-dataformat-xml), where it may or may not make sense. Jackson does not handle XML as DOM nodes, for example; and all logical manipulation occurs via streams of JsonToken
s. Some information on attribute/element is retained, but not a lot.
At the same time, adding something to decorate attributes with @
prefix could be possible.
As long as there is some xml attribute syntax it would suffice since json and xml have their own mapper
For suggestions for features to add to XML module, an issue would need to be created at
Side note: what is currently the way to do node.at("/a/b").asText() for that xml?
The original case is not something Jackson supports, due to name collision (or, rather, I think both attribute b
and element b
s values would be combined, depending on target type -- for JsonNode
become an array value).
But if there was a feature to use @
prefix, you'd use
node.at("/a/@b").asText();
for attribute and
node.at("/a/b").asText()
for element.
Okay, I'll open the issue soon then, thanks
In a project we're trying to interpret either Json or XML depending on what the user gives as entry data, along with some paths to the document.
We're using Jackson and the dataformat-xml and choose the mapper via a flag, but the path syntax doesn't seem to allow grabbing attributes with @, like in xpath syntax, example:
xml = "<a b=\"attrib\"><b>node</b></a>"
and as path:
"/a/@b"
for the attribute and"/a/b"
for the node