我必须在两个列表的元素之间进行引用。我尝试过使用 XStream。以下是 XML 的示例:
<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>
以及我的 Java 类的一些划痕:
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 放入类时,我都会在 Author autor 字段中得到空值。也许我需要更多注释,但我在 Xstream 文档中没有找到任何内容。