这是关于snakeyaml 1.11和yaml。
当我转储带有扩展通用映射的属性的bean时,snakeyaml崩溃。
这是一个扩展的通用地图:
public static class MyStupidHash<T> extends java.util.HashMap<String, T>
{
}
这是一个具有属性snakeyam无法转储的bean:
public class FactoryOfStupid
{
public MyStupidHash<Integer> getStupid()
{
return new MyStupidHash<Integer>();
}
}
当我使用snakeyaml转储FactoryOfStupid对象时,我得到:
java.lang.ArrayIndexOutOfBoundsException: 1
at org.yaml.snakeyaml.representer.Representer.checkGlobalTag(Representer.java:204)
at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:144)
at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:83)
at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:49)
at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:109)
at org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:65)
at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:270)
at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:261)
at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:233)
at org.yaml.snakeyaml.Yaml.dump(Yaml.java:209)
以下是所有junit测试:
/*
*/
package unitaire;
import java.util.HashMap;
import org.junit.*;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
/**
*
* @author herve
*/
public class YamlRepresenterUnitTest
{
public YamlRepresenterUnitTest()
{
}
@BeforeClass
public static void setUpClass() throws Exception
{
}
@AfterClass
public static void tearDownClass() throws Exception
{
}
@Before
public void setUp()
{
}
@After
public void tearDown()
{
}
@Test
public void onMyStupidHash() throws Exception
{
MyStupidHash<Integer> shash;
Yaml yaml;
String txt;
DumperOptions options;
FactoryOfStupid fact;
fact = new FactoryOfStupid();
shash = fact.getStupid();
shash.put("toto", new Integer(10));
options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
yaml = new Yaml(options);
txt = yaml.dump(fact);
System.out.println("txt="+txt);
}
public static class MyStupidHash<T> extends java.util.HashMap<String, T>
{
}
public class FactoryOfStupid
{
public MyStupidHash<Integer> getStupid()
{
return new MyStupidHash<Integer>();
}
}
}
在snakeyaml中是否有一个神奇的选择来转储这类东西?
感谢。