Mause / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

Ability to customize anchor names #202

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to be able to define custom anchors based on a map of 
object->string in a subclass of `Serializer`.  However `Serializer` is final 
and `generateAnchor` is private.  Also, there is no hook in `Yaml` to provide a 
custom class for serializing.

*Approach A*

Please make `Serializer` non-final and `generateAnchor` protected, and provide 
an optional ctor-set field in `Yaml` to pass in a subclass of `Serializer`.  
Lastly, update `generateAnchor` to get a copy of the object represented by 
`Node`.

I picture being able to write something like:

@Override protected String generateAnchor(Object original) { if (this.myCustomAnchors.containsKey(original)) { return this.myCustomAnchors.get(original); } else { return super.generateAnchor(original); } }


But I am unsure how to get at the original object represented by a node.

*Approach B*

Provide some kind of mapping in snakeyaml itself for object->alias, a hook for 
defining custom text to use as anchors.

I figure approach B is about the same work as the approach A: still is needed 
the machinery described above.  Not sure what approach is most consistent with 
current Yaml API.

Cheers,
--binkley

Original issue reported on code.google.com by b.k.ox...@gmail.com on 5 Jan 2015 at 1:57

GoogleCodeExporter commented 9 years ago
Feel free to provide a patch with the proposed API and tests.

Original comment by py4fun@gmail.com on 6 Jan 2015 at 8:25