0

It's about snakeyaml 1.11 and yaml.

When I dump a bean with a property with an extended generic map, snakeyaml crash.

Here is an extended generic map :

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

Here is a bean with properties snakeyam can't dump :

  public class FactoryOfStupid
  {
    public MyStupidHash<Integer> getStupid()
    {
      return new MyStupidHash<Integer>();
    }
  }

When I dump a FactoryOfStupid object with snakeyaml, I get :

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)

Here is all the junit test :

/*
 */
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>();
    }
  }
}

Is there a miraculous option in snakeyaml for dump this sort of things ?

Thanks.

4

1 回答 1

0

可以关注SnakeYAML 项目的进展

于 2012-03-02T22:22:23.717 回答