EclipseLink JAXB (MOXy)의 @XmlPath
매핑을 사용하여이 사용 사례를 매핑 할 수 있습니다. 아래 예제와 비교하여 @XmlElementWrapper
을 사용하는 방법과 비교하여 설명하겠습니다.
루트
package forum13268598;
import java.util.List;
import javax.xml.bind.annotation.*;
import org.eclipse.persistence.oxm.annotations.XmlPath;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Root {
@XmlElementWrapper(name="line-items-element-wrapper")
List<LineItem> item1 = null;
@XmlPath("line-items-xml-path/item1")
List<LineItem> item2 = null;
}
jaxb.properties
은 JAXB 공급자로 MOXY를 사용하려면 파일을 포함 할 필요가 다음 항목을 사용하여 도메인 모델과 동일한 패키지에 jaxb.properties
라고 (http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html 참조).
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
데모
package forum13268598;
import java.util.ArrayList;
import javax.xml.bind.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Root.class);
Root root = new Root();
root.item1 = new ArrayList<LineItem>();
root.item2 = new ArrayList<LineItem>();
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(root, System.out);
}
}
요소가 빈 컬렉션 기입되어있는 @XmlElementWrapper
사용의 경우 출력
,하지만 @XmlPath
사용 사례 아닙니다.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<line-items-element-wrapper/>
</root>