我有一個需要映射到Java對象(即DTO)的XML。我的XML有不有我的DTO任何Java對象的一些包裝元素..我的XML看起來像這樣無法使用Jaxb和XMLPath對XML進行解組
<UseCaseView>
<FindCandidates>
<CandidatesRequest>
<APIRequest>
<Code>Code</Code>
</APIRequest>
</CandidatesRequest>
</FindCandidates> </UseCaseView>
的「FindCandidates」和「CandidatesRequest」只是包裝元素和「APIRequest」再次一個DTO ..
我使用xmlpath中像這樣在我的DTO ..我的DTO是這樣的..
@XmlRootElement(name = "UseCaseView")
public class FindRequestDTO implements Serializable{
private static final long serialVersionUID = 5528726225975606325L;
private ApiRequestDTO apiRequest;
@XmlPath("FindCandidates/CandidatesRequest/APIRequest")
public ApiRequestDTO getAPIRequest() {
return apiRequest;
.........
這不是APIRequest元素映射到我的ApiRequestDTO,如果我刪除了兩個包裝元素和 直接使用XMLElement( NAME =「APIRequest」),它的工作......但我需要忽略這兩個包裝元素,構建我的DTO .. 我已經加入了Jaxb.properties與
"javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory"
在我的資源文件夾中文件
。
有人可以幫助我知道怎麼回事錯在這裏..
感謝,
:當使用本機API,你不需要
jaxb.properties
文件?以下示例可能有所幫助:https://github.com/bdoughan/blog20110908。如果沒有,我明天會發布答案。 – 2012-03-26 23:27:32@Blaise - thx快速回復..返回的實現類是com.sun.xml.bind.v2.runtime.JAXBContextImpl – sampath 2012-03-26 23:36:58
您的類路徑中是否有eclipselink.jar?我在之前的評論中鏈接到的示例都是使用Maven進行編譯和運行的設置。 – 2012-03-26 23:42:44