YAML - 一对多对象图

发布于 2024-09-11 03:26:17 字数 1129 浏览 5 评论 0原文

我使用基于 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 

RuntimeException 发生:无法加载固定装置 test-data.yml: null; 无法为 !models.Role 构造 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

I use a snakeyaml (java) based parser to write a test case, and couldn't figure out how to properly build the graph. Any help, highly appreciated. thanks.

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

the above exception is for an unrelated field, and it works if I
remove the association

roles: 
  - roleType: testRoleType 
    description: desc 

If I change it to

- !models.Role 
      roleType:         testRoleType 
      description: desc 

RuntimeException occured : Cannot load fixture test-data.yml: null;
Can't construct a java object for !models.Role; exception=onRole
Any help, highly appreciated. thanks.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里泪两行 2024-09-18 03:26:17

1) 创建图表

2) 使用 SnakeYAML 序列化对象:

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

3) 查看结果并手动更改它。

PS !models.Role 是一个本地标签,您应该指示 SnakeYAML 如何管理它。

1) create your graph

2) Use SnakeYAML to serialize the object:

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

3) see what comes out of it and change it manually.

P.S. !models.Role is a local tag and you should instruct SnakeYAML how to manage it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文