2010-07-20 5 views
0

나는 snakeyaml (java) 기반 파서를 사용하여 테스트 사례를 작성하고 그래프를 올바르게 작성하는 방법을 알 수 없었다. 어떤 도움, 높게 평가. 감사.YAML - 일대 다 객체 그래프

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

위의 예외가 관련이없는 필드, 그리고 내가

- !models.Role 
     roleType:   testRoleType 
     description: desc 

의 RuntimeException가 발생

로 변경하는 경우 나 협회

roles: 
    - roleType: testRoleType 
    description: desc 

을 제거 경우 작동 : 고정을로드 할 수 없습니다 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 

답변

1

1) 객체를 직렬화 그래프

2) 사용 SnakeYAML을 만듭니다

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

3)이 나오는 것을보고 수동으로 변경합니다.

P. ! models.Role은 로컬 태그이며 SnakeYAML에게 관리 방법을 지시해야합니다.