2011-05-10 3 views
2

안녕이이 정의 스키마 :JAXB는 EclipseLink 문제

<complexType name="x"> 
    <sequence> 
     <element name="year" type="date"/> 
       <choice> 
        <element name="comuneNascita" type="string" nillable="true"/> 
        <element name="statoNascita" type="string" nillable="true"/> 
       </choice> 
    </sequence> 
</complexType> 

마샬 시도 (xjc를 가진 : 간단한 옵션) xjc를 생성 클래스 때 나는이 결과를 얻을 수 :

[...] 
    <statoNascita xsi:nil="true"/> 
    <comuneNascita>xxx</comuneNascita> 
    [...] 

정말 잘못되었습니다.

nillable = "true"를 제거하면이 문제를 해결할 수 있지만 유효하지 않은 요소를 지정해야합니다. 해결 방법은 없습니까?

당신과 같이 주석 속성을 가진하여 문제를 방지 할 수 있습니다

답변

0

은 다음과 같습니다

@XmlElements({ 
    @XmlElement(name="comuneNascita", type=String.class), 
    @XmlElement(name="statoNascita", type=String.class), 
}) 

당신은 XJC은 JAXB 바인딩 파일을 사용하여 위와 같이 주석 속성 생성 할 수 있습니다 : 들어

<?xml version="1.0" encoding="UTF-8"?> 
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" 
      version="2.1"> 
    <globalBindings choiceContentProperty="true"/> 
</bindings> 

을 추가 정보

+0

일부 속성에 대해 JaxElement 유형 생성을 피하려면 아직 옵션을 사용하지 않은 경우에만 해당됩니다. 이 경우 choiceContentProperty = "true"옵션은 무시됩니다. 나는이 같은 스키마 변경했다이 문제를 방지하려면 : <선택에 minOccurs = "0"> \t <요소 이름 = "comuneNascita"유형 = "문자열"/> \t <요소 이름 = "statoNascita"유형 = "string"/> 그래서 null 요소는 xsi : nil로 마샬링되지 않습니다. 그러나 때로는 스키마를 변경하는 것이 옵션이 아닙니다. – Massimo