Search code examples
javasnakeyaml

How do I best go about loading non-bean objects from SnakeYaml


SnakeYAML easily dumps/loads javabean objects, but what about objects that I don't want to be beans for readability's sake?

I think what I need is a named array. Something that stores an object like so:

Rectangle: id: 1233154 width: 14 height: 15 x: 1 y: 0

How do I do that using snake yaml?

As of now, I use recursion/inheritance with objects to allow themselves to write xml.


Solution

  • What you do in this case is make your objects generate maps for the attributes of each object, this will work fine as the SnakeYAML library has support for maps.