- changed status to new
Dump without anchors
Dumping YAML will automatically create anchors if the same object occurs multiple times in the input. It would be good to be able to disable this feature.
Comments (20)
-
-
the feaure is there also to support recursive structures
-
reporter Yes, and it’s reasonable to have it enabled by default. But I have a specific use case where I need to disable it.
-
I am nor sure about the consequences of such deviation. Defunety, it goes against the YAML spec.
I will have a look.
-
It will also mean that parsing will create different instances (where it was one instance)
-
-
is it what you expect to achieve ? I see the consequence that recursive structures cause StackOverFlow
-
reporter Yes, that’s what I want.
And yes, I am aware of the risk of recursive structures. Ideally, it would detect recursive structures and throw some exception (before stack overflow), but it’s good enough for me if it doesn’t.
-
It seems to be rather easy to do it for simple objects, but recursive ones is a problem in current implementation.
We are not currently tracking recursion status of object references during dump as it is irrelevant when anchors are used.
We need to check what would be an impact on code base if we want to play nicely while introducing this feature. -
reporter Wouldn’t it be possible to use the existing anchor tracking to detect recursive objects?
I think that a reasonable implementation would throw an exception if recursion is detected, it doesn’t need to produce any output in that case.
-
feat: add dereferenceAliases to DumperOptions
Setting this property to true will force emitter to dereference aliases: emit Node referenced by the Alias instead of Alias itself. The Anchors are not emitted also.
Default value is true to preserve current behavior aligned with specs.
If serializer "detects" recursive structure it fails with SerializationException.
Implementation is on the Serialize level meaning that Nodes are always constructed with Anchors and Aliases.
There is no test with Merge Nodes.
see
#1086→ <<cset 64453675d543>>
-
PR#72 should kind of bring what you ask.
-
- changed status to resolved
merged to master.
Use
DumberOptions.setDereferenceAliases
. Remember that tree of Nodes will still have all Anchor Nodes: de-referencing happens during Serialization of the tree. -
It will be delivered in version 2.3
-
reporter Nice, thanks!
-
When will 2.3 likely be released? We also need this feature, so even a snapshot release would be greatly appreciated!
-
You can build the version.
Unfortunately, the certificate which is required to upload to Sonatype expired. We need to create and promote new one. I will do my best to do it this summer.
-
@Floris Westerman feel free to try snapshot:
https://oss.sonatype.org/content/repositories/snapshots/org/yaml/snakeyaml/
-
Excellent, thank you so much! This saves quite some trouble manually setting up the dependencies.
-
you do not need to. Just run Maven wrapper:
./mvnw clean package
- Log in to comment