JAXB无法识别类型只是在架构中放置xs:anyType

时间:2013-04-19 12:59:54

标签: java xml jaxb xsd

如何在下面的示例中强制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”

0 个答案:

没有答案