为 Java 类添加JAX-B
Java 注释时 - 如果我有一个父Class Entry,有两个孩子Book和JournalArticle,
我会为所有三个类添加这些注释:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
IE:
@XmlSeeAlso({au.com.library.Book.class, au.com.library.JournalArticle.class})
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public abstract class Entry implements Serializable{
private static final long serialVersionUID = -1895155325179947581L;
@XmlElement(name="title")
protected String title;
@XmlElement(name="author")
protected String author;
@XmlElement(name="year")
protected int year;
和
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Book extends Entry {
@XmlElement(name="edition")
private String edition;
@XmlElement(name="publisher")
private String publisher;
@XmlElement(name="placeOfPublication")
private String placeOfPub;
和
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class JournalArticle extends Entry {
@XmlElement(name="journalTitle")
private String journalTitle;
@XmlElement(name="volume")
private String volume;
@XmlElement(name="issue")
private String issue;
@XmlElement(name="pageNumbers")
private String pgNumbers;