YAML - 一对多对象图
我使用基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 创建图表
2) 使用 SnakeYAML 序列化对象:
3) 查看结果并手动更改它。
PS !models.Role 是一个本地标签,您应该指示 SnakeYAML 如何管理它。
1) create your graph
2) Use SnakeYAML to serialize the object:
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.