-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
YAML Anchors / References #98
Comments
Seems like anchor/reference bugs affect quite a few people: OpenAPITools/openapi-generator#1593 |
Same here. I just switched my code to snakeyaml because that handles anchors/refs correctly. Which is strange because jackson-dataformats-yaml is using snakeyaml internally |
@nkiesel Limitation is a combination of multiple things, but basically SnakeYAMLs incremental part only exposes information about anchors, references, but does no resolution as far as I know. This means that Jackson needs to do that part. But since databinding is format-agnostic, it can only operate in a way general data model works, and for that Object Id handling is opt-in on per-type (or per-property sometimes) basis. This because JSON does not have concept natively and support for identity has been added by requiring annotations (partly since there was/is no real standard for specifying concept; and partly since there is non-trivial overhead for having to keep track of every value in whole input for possible back reference). One thing that might make sense is to see if higher level SnakeYAML API might allow pre-processing references. I'll create issue for that. |
Created 2 new issues to possibly address this:
|
I have a similar issue. I parse my swagger file with this library. I will have to use snakeyaml as an alternative. +1 to fix this, view the exposed anchor at the very least, navigate to the referred anchored or inline it if possible. |
@odupuy One specific problem is that while streaming api ( But at the same time, adding overhead of every node potentially having anchor is problematic, so perhaps there should be separate |
Thanks for your answer @cowtowncoder. I cannot comment much on what it is effectively doable in this lib but I will keep an eye on the issue. In the meantime SnakeYml allows me seeing both anchor and reference (they are inlined) so I will switch to this one. |
@odupuy Makes sense; you need to use something that does what you need. But one thing I realized last night, which might allow a reasonable solution is this: instead of trying to solve this via sub-classing (inheritance), with its known problems, how about composition? So: addition of a new type of node -- "reference node"? "metadata node"? "info wrapper"? -- that would effectively contain additional metadata, and reference to "real" value node. Metadata being tracked could be combination of general info (Location, if required; Object and/or Type Ids) and possibly additional Opaque one (backend-dependant), with key/value. This would be sizable addition so I can't promise much about implementing it soon, but I am excited that it feels like it could be the way forward. This is a long-standing issue affecting multiple backends (for XML, distinction between Elements and Attributes matters, f.ex) so some new approach would be very welcome. |
I was thinking about something similar while replying. A new type of node should be OK and without risks. Simply a text reference to the referred anchor or for an anchor to the referrer(s) would help. Additional direct navigation could be handy as long as there is no side effect making you recursively exploring the tree (not sure if toString() would do that) |
One possibility on resolving references could be a separate entity or helper that will traverse tree, modify it to resolve anchor/refs -- it is something that can not be done easily during reading due to possible forward references (... assuming YAML allows those?). Jackson does handle it incrementally with And doing it as separate pass would allow format-specific handling, too, in case semantics vary across formats (which they do) -- in theory, could even support XML specific identity that way. |
YAML only allows backward references: spec says "It is an error for an alias node to use an anchor that does not previously occur in the document." ("alias" node here is the usage of a reference, and "anchor" is it's definition). However, it is allowed to redefine anchors. Thus as I see it, a single pass could resolve all the references. |
This allows anchors and references to be used in all configuration files. The implementation is a workaround for jackson-dataformats-text bug #98: FasterXML/jackson-dataformats-text#98
Apparently they've started using Anchors and Aliases in yml files upstream (see e.g. uk.yml -> male_first_name -> first_name). Seems like jackson can't handle Anchors properly (see FasterXML/jackson-dataformats-text#98) As a workaround, we use snakeyaml to read .yml files to Map objects, and then we use jackson to write them to .json files, since snakeyaml seems to support anchors just fine without needing to jump through hoops.
Apparently they've started using Anchors and Aliases in yml files upstream (see e.g. uk.yml -> male_first_name -> first_name). Seems like jackson can't handle Anchors properly (see FasterXML/jackson-dataformats-text#98) As a workaround, we use snakeyaml to read .yml files to Map objects, and then we use jackson to write them to .json files, since snakeyaml seems to support anchors just fine without needing to jump through hoops.
Apparently they've started using Anchors and Aliases in yml files upstream (see e.g. uk.yml -> male_first_name -> first_name). Seems like jackson can't handle Anchors properly (see FasterXML/jackson-dataformats-text#98) As a workaround, we use snakeyaml to read .yml files to Map objects, and then we use jackson to write them to .json files, since snakeyaml seems to support anchors just fine without needing to jump through hoops.
Hi there, first of all thanks heaps for your awesome work with Jackson.
I am trying to get a concise configuration out of a yaml file, but I am pretty stuck at the moment.
I have followed many issues and still did not managed to get it working using only
@JsonIdentityInfo
By the this tests it should be as simple as annotating
Environment
class with@JsonIdentityInfo(generator = ObjectIdGenerators.StringIdGenerator.class)
but that also did not work.After reading this issue i thought it could be the scope, so I have annotated the
environment
andbundle1
properties adding the mainConfiguration
class as scope but that also yield not success.Is this possible today, if it is how can it be achieved, and if not what do you recommend?
As the issue 266 suggests, I should write my own
DeserializationContext
, and figure out a way to find the references. But "you" --I believe it is you-- recommended this before.Which of these two should I follow if there is no simple way to get it working with the current 2.9.6 version?
Trying to debug I did not see any calls to
bindItem
which means thatSimpleObjectIdResolver._items
are always null, even though I can see the references being set what would trigger that line to be called? Please keep in mind that I don't claim to know anything about jackson, that was what I could gather from trying to debug it.PS. Like the tests I have also tried the anchoring as a prefix, but it seems that the library have no issues finding both ways.
Thanks again.
The text was updated successfully, but these errors were encountered: