문제
나는 초록 수업이 있습니다.
@XmlSeeAlso({AndQuery.class, OrQuery.class, NotQuery.class, PropertyQuery.class, MultiQuery.class})
@XmlRootElement
public abstract class Query {
이 클래스에는 하위 클래스가 있습니다.
public abstract class MultiQuery extends Query {
그리고이 마지막 슈퍼 클래스에는 @xmlrootnode와 주석이 달린 and query와 orquery의 두 가지 서브 클래스도 있습니다.
또한 쿼리 슈퍼 클래스를 확장하는 PropertyQuery 클래스가 있습니다.
내가 다음과 같은 게시물을 할 때는 괜찮습니다.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<orQuery>
<query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="propertyQuery">
<propertyName>SenderContractNumber</propertyName>
<propertyValue>D*</propertyValue>
</query>
<query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="propertyQuery">
<propertyName>SenderContractNumber</propertyName>
<propertyValue>A*</propertyValue>
</query>
<query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="andQuery">
<query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="propertyQuery">
<propertyName>documentNumber</propertyName>
<propertyValue>222</propertyValue>
</query>
<query xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="propertyQuery">
<propertyName>documentNumber</propertyName>
<propertyValue>222</propertyValue>
</query>
</query>
</orQuery>
내가 원하는 것은 다음과 같이 XML을 게시하는 것입니다.
<orQuyery>
<query>...</query>
<andQuery>
<query>...</query>
</andQuery>
</orQuery>
내가 위에 놓은 것의 초안.
내 Orquery 클래스가 쿼리 노드 만 볼 수 없기 때문에 주석을 달아야 할 것을 제발 말해 줄 수 있습니까?
도와주세요...
정말 감사합니다
해결책
많은 쿼리에 다른 쿼리가 포함되어있는 것처럼 들립니다. 말하자면, 여러분은 다른 쿼리 목록을 포함하기를 원합니다.
유형 쿼리 목록 만있는 경우 JAXB는 목록에 어떤 유형의 쿼리를 넣을지 결정할 수 없습니다. 목록에 포함 할 수있는 내용에 대한 모든 옵션을 지정할 수 있습니다. 이런 식으로 지정된 유형의 유형을 허용하기 위해 생성 된 스키마.
예시:
@XmlElements({
@XmlElement(type=AndQuery.class),
@XmlElement(type=OrQuery.class),
@XmlElement(type=NotQuery.class),
@XmlElement(type=PropertyQuery.class),
@XmlElement(type=MultiQuery.class)
})
List<Query> queries;
제휴하지 않습니다 StackOverflow