代码之家  ›  专栏  ›  技术社区  ›  bsr

YAML-一对多对象图

  •  0
  • bsr  · 技术社区  · 14 年前

    我使用一个基于snakeyaml(java)的解析器来编写一个测试用例,但是我不知道如何正确地构建这个图。任何帮助,非常感谢。谢谢。

    RuntimeException occured : Cannot load fixture test-data.yml: 
    org.hibernate.PropertyAccessException: could not get a field value by 
    reflection getter of models.Priority.description
    

    上面的异常是针对一个不相关的字段,如果我 删除关联

    roles: 
      - roleType: testRoleType 
        description: desc 
    

    如果我把它改成

    - !models.Role 
          roleType:         testRoleType 
          description: desc 
    

    无法为构造java对象!模型.角色;异常=onRole 任何帮助,非常感谢。谢谢。

    public class Person {
    String fullname;
    
    @OneToMany(cascade=CascadeType.ALL)
    public List<Role> roles;
    }
    
    public class Role {
    public RoleType roleType;
    public String description;
    }
    
    public class RoleType {
    public String roleName;
    public String description;
    }
    
    
    YAML--
    
    RoleType (testRoleType):
        roleName:      test
        description:   desc
    
    Person(administrator):
        fullname:       Administrator
        roles:
          - roleType: testRoleType
            description: desc
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Andrey    14 年前

    1) 创建图形

    2) 使用SnakeYAML序列化对象:

    JavaBeanDumper dumper = new JavaBeanDumper();
    String output = dumper.dump(graph);
    

    3) 看看会有什么结果,然后手动更改。

    附笔!模型.角色是本地标记,您应该指示SnakeYAML如何管理它。