http://stackoverflow.com/questions/3422545/binding-a-generic-java-class-to-a-json-using-jaxb 可能需要翻墙才可以访问 @XmlRootElement @XmlSeeAlso(DataClass.class) public static class EnvelopeClass<T> { @XmlElement public String version; @XmlElement public T data; EnvelopeClass() { } EnvelopeClass(String version, T data) { this.version = version; this.data = data; } } @XmlRootElement public static class DataClass { @XmlElement public String name; DataClass() { } DataClass(String name) { this.name = name; } } import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "data") public class DataClass { @XmlElement public String name; DataClass() { } DataClass(String name) { this.name = name; } } demo import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(EnvelopeClass.class); DataClass data = new DataClass("myName"); EnvelopeClass envelope = new EnvelopeClass<DataClass>("1.0", data); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(envelope, System.out); } }