如何在下面的示例中强制JAXB识别实际类型,因为它在生成xml架构时创建xs:anyType
实施班级
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Response", propOrder = { "message", "companies", "resultsCount",
"exceptionMessage" })
@XmlSeeAlso({CompanyV8.class})
public class ResponseV8 extends Response<CompanyV8> {
}
父类
@XmlTransient
public abstract class Response<T extends CompanyDraft> {
private String message;
@XmlElement(name = "company")
private List<T> companies;
private Integer gisResultsCount;
private String exceptionMessage;
模型类
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Company", propOrder = { "id", ...omitted... })
public class CompanyV8 extends CompanyDraft {
@XmlElement
private String BvDId;
@XmlElement
private String globalHeadquarterBvDId;
@XmlElement
private String parentHeadquarterBvDId;
@XmlElement
private String domesticHeadquarterBvDId;
@XmlElement
private List<BusinessPartnerSegmentDetailedV8> businessPartnerSegment;
xml架构
<xs:sequence>
<xs:element minOccurs="0" name="message" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="company" type="xs:anyType"/>
<xs:element minOccurs="0" name="gisResultsCount" type="xs:int"/>
<xs:element minOccurs="0" name="exceptionMessage" type="xs:string"/>
</xs:sequence>
就像你可以看到JAXB创建的type =“xs:anyType”而不是type =“tns:Company”