Closed GoogleCodeExporter closed 9 years ago
From the Metadata.java it looks like BeanAccess.FIELD might work for you.
For dumping and for loading since there is nothing special done in setters.
But it was brief look ;) So you better try yourself.
Yaml.setBeanAccess(BeanAccess.FIELD)
-alex
Original comment by alexande...@gmail.com
on 16 Nov 2010 at 7:18
Thank you very much Alex,
I tried your tip, and it works well for a simple example. Here's the test:
Yaml y = new org.yaml.snakeyaml.Yaml()
y.setBeanAccess(org.yaml.snakeyaml.introspector.BeanAccess.FIELD)
Metadata met = new Metadata();
met.set("met1", "whatever")
met.set("met2", "something")
met.add("met2", "something else");
y.dump(m)
!!org.apache.tika.metadata.Metadata
metadata:
met1: [whatever]
met2: [something, something else]
But I still have to learn how to properly load it!!
y.load(FileInputStream(File("metadata.yml")))
Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList
cannot be cast to [Ljava.lang.String;
Thanks again,
Regards
jg
Original comment by jgrand...@gmail.com
on 16 Nov 2010 at 8:37
This issue was updated by revision 191ab72b39.
GenericProperty.class fails to identify type when Collection's parameter is an
Array.
Workaround: use TypeDespriptor to specify correct PropertyType
Original comment by alexande...@gmail.com
on 16 Nov 2010 at 12:28
This issue was closed by revision fa3b0e3d2a.
Original comment by alexande...@gmail.com
on 16 Nov 2010 at 12:28
It should work now. You can use either latest sources or something like this
with 1.7:
TypeDescription aTypeDescr = new TypeDescription(Metadata.class);
aTypeDescr.putMapPropertyType("meta", String.class, String[].class);
Constructor c = new Constructor();
c.addTypeDescription(aTypeDescr);
Yaml yaml2load = new Yaml(c);
yaml2load.setBeanAccess(BeanAccess.FIELD);
yaml2load.load(....)
See http://code.google.com/p/snakeyaml/wiki/Documentation#Type_safe_collections
Original comment by alexande...@gmail.com
on 16 Nov 2010 at 12:34
You can also try the latest snapshot:
https://oss.sonatype.org/content/groups/public/org/yaml/snakeyaml/
Original comment by py4fun@gmail.com
on 16 Nov 2010 at 1:49
Please be aware that you do not have to use global tags (with the class name).
You can find an example in the tests (testNoTags):
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/issues/issue95/ArrayInGenericCollectionTest.java
Original comment by py4fun@gmail.com
on 16 Nov 2010 at 3:10
Original issue reported on code.google.com by
jgrand...@gmail.com
on 16 Nov 2010 at 5:34