Question

Is there a YAML driver for the Java XStream package?

I'm already using XStream to serialise/deserialise both XML and JSON. I'd like to be able to do the same with YAML.

Was it helpful?

Solution

To parse a YAML document you can use this chain: YAML -> SnakeYAML -> Java -> Your Application (-> XStream -> XML)

Emitting YAML is simpler and there are a couple of options: 1) Your Application -> XStream with Custom Writer -> YAML 2) Your Application -> SnakeYAML -> YAML

The second option does not require any additional development.

OTHER TIPS

You might find that helpful to get a direction: XStream - how to serialize objects to non XML formats

I used JYAML and it worked great. I know it doesn't directly answer your question but it works well.

While XStream is pretty nice for XML, JSON it produces is rather ugly, due to conversion using Badgerfish notation.

But you could consider using Jackson for all 3; since while the default package just handles JSON, there are extensions for both XML and YAML, and all work using same powerful data-binding functionality, just differ on low-level parsers and generators (for XML, Stax API is used)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top