내 프로젝트 중 하나에서 계약 우선 웹 서비스를 사용하는 JAXB2 marshaller를 사용하여 XML 스키마에서 객체를 생성합니다.JAXB Java 및 XSD 매핑
모든 것이 잘 작동합니다. 그러나 "코드 사용성"문제가 있습니다. 내가 한 가지 예를 들어 보겠다.
스키마 :
<xs:complexType name="personContractAlertListType">
<xs:sequence>
<xs:element ref="PersonContractAlert" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="PersonContractAlertsResponse">
<xs:complexType>
<xs:sequence>
<xs:element ref="PersonContractAlertList"/>
</xs:sequence>
</xs:complexType>
</xs:element>
그래서 내가 전화를해야 PersonContractAlerts
목록에 액세스하려면 : 좀 긴
PersonContractAlertsResponse.getPersonContractAlertListType().getPersonContractAlert()
합니다.
내 질문은 : 나는 getPersonContractAlertListType()
제거하고 직접 가서 얻을 수있는 방법 : 그 래퍼 요소는 XSD 정말이기 때문에 내가 자바 객체에 필요하지 않은, PersonContractAlertsResponse.getPersonContractAlert()
.
<Element1>
<Wrapper>
<Element2/>
</Wrapper>
</Element1>
을 그리고 난에 매핑 자바에서 원하는 : 즉
는이 Element1.getElement2()
아마 사용 JAXB 어댑터. 그리고 나는 생성 된 객체를 만지기를 원하지 않는다는 것을 기억하십시오. 이것은 마샬 러 설정 (adaptor, interceptor 등) 또는 XSD (어쩌면 조작 할 수있는 설정이 있음)에서 수행되어야합니다.
고맙습니다.
는 UPDATE :
는 좀 바인딩 작업에 튜토리얼을 발견 :
https://jaxb.dev.java.net/guide/Using_different_datatypes.html
내가 JAXB 바인딩을 사용해보십시오 연구 할 것이다.
이 링크는 현재 https://jaxb.java.net/guide/Using_different_datatypes.html –