Snakeyml:具有泛型扩展映射的属性



这是关于snakeyaml 1.11和yaml的。

当我转储一个带有扩展泛型映射的属性的bean时,snakeyaml崩溃。

这是一个扩展的通用地图:

  public static class MyStupidHash<T> extends java.util.HashMap<String, T>
  {    
  }

这是一个特性蛇不能倾倒的豆子:

  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有一个神奇的选择来倾倒这种东西吗?

谢谢。

您可以跟踪SnakeYAML项目的进度