如何强制 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"