views:

202

answers:

2

First of all, Merry Christmas to everyone!

Now to my question: Let's say I have the class Outer with some inner class Inner. As a field in Outer, I have a List<Inner>, which i then want to dump to a YAML file. I do this like so:

Outer o = new Outer();
o.innerList = new ArrayList<Inner>();
o.innerList.add(new o.Inner());
...
Yaml.dump(o, new File("test.yml");

This gives me the exception: Exception in thread "main" org.ho.yaml.exception.ObjectCreationException: Error near line 0: Can't create object of type class game.Outer$Inner using default constructor.

I tried providing a custom constructor and changing the access level to public, to no help. Any ideas?

A: 

First thing is check that YAML supports the Inner class serialization.

MCA
+1  A: 

SnakeYAML has a lot of examples with inner classes. How does the YAML document (test.yml) look like ? Is Inner a static inner class ?

I'm trying to serialize to see how the output will look like, in order to create my own documents for parsing. No, Inner is not static. I will have a look at SnakeYAML.
pg-robban
I am afraid it is not possible if the inner class is not static. There is not way to represent the link to its parent in a YAML document.
You may try to serialize to XML first to see whether it is visible.If it possible to create XML it is possible to create YAML.
I tried SnakeYAML and it seems to be working if I add a public modifier to the class. It even seems to be working if I put a static modifier to the class.
pg-robban