0

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?

pg-robban
  • 1,395
  • 4
  • 21
  • 42

2 Answers2

0

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

Murat Can ALPAY
  • 520
  • 2
  • 17
0

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

Andrey
  • 2,931
  • 22
  • 18
  • 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 Dec 25 '09 at 01:18
  • 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. – Andrey Dec 25 '09 at 11:15
  • 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. – Andrey Dec 25 '09 at 14:07
  • 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 Dec 25 '09 at 15:41