0
두 목록의 요소를 참조해야합니다. XStream을 사용해 보았습니다.XStream에서 두 목록을 서로 참조하는 방법은 무엇입니까?
<bookshop>
<authors>
<author id="a1">
<name>Stanisław</name>
</author>
</authors>
<books>
<book id="b1">
<author>a1</author>
<title>Ubik</title>
<price currency="PLN">29.0</price>
</book>
</books>
</bookshop>
내 자바 클래스의 약간의 흠집 : 나는 저자 저자에 필드에 널 얻을 클래스로 XML을 넣어려고
public class Bookshop {
private ArrayList<Author> authors;
private ArrayList<Book> boooks;
}
public class Book {
@XStreamAsAttribute
private String id;
private Author author;
private String title;
private Price price;
}
@XStreamConverter(value=ToAttributedValueConverter.class, strings={"value"})
public class Price {
private double value;
@XStreamAsAttribute
private String currency;
}
public class Author {
@XStreamAsAttribute
private String id;
private String name;
private String surname;
}
그리고 매번 다음은 XML의 예입니다. 어쩌면 내가 더 많은 주석이 필요하지만 Xstream 문서에서 아무것도 발견하지 못했습니다.
감사합니다. 물론 틀렸어. 나는 실수로 붙여 넣기/잘라 내기를했다. 미안하다. 그리고 Converter에 대한 나의 의심을 확인해주었습니다. 그래서 나는 좋은쪽으로 가고 있습니다. – user1964668
그러나 왜 변환기가 필요한지 모르겠지만 모든 것이 그대로 작동합니다 ('Bookshop'의 직렬화 및 비 직렬화). 물론 내가 보지 못하는 프로젝트의 측면이있을 수 있습니다. – atomman
네, 잘 작동하지만 xml 파일로 제한됩니다. 이 파일은이 그림에서' '라는 참조를 포함 할 수 없으며, 이런 식으로는 ' a32 '입니다. –
user1964668