ยกเลิกการจัดเรียงแท็ก xml ด้วย Jersey

ฉันมี xml นี้:

<?xml version="1.0" encoding="utf-8"?>
 <ProductItem xmlns="http://providers.natinst.com/pdi-rest/1.0/meta/" urn="urn:product-item:910796-76" url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76.xml">
<partNumber>910796-76</partNumber>
<inventoryItemId>560427</inventoryItemId>
<nicInventoryItemId>765430</nicInventoryItemId>
<name />
<description>LABVIEW CORE 2 SELF-PACED ONLINE TRAINING (6 MONTHS ACCESS)</description>
<isCustomerFacing>true</isCustomerFacing>
<itemType>CE</itemType>
<partType>Training Program</partType>
<bookingsClassName />
<bookingsClassCode />
<lifecyclePhase>Released</lifecyclePhase>
<salesClass />
<firstOrderableDate />
<locale>en-US</locale>
<ngpmProductHierarchy />
<productRevisions url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76/productRevisions.xml" />
<serviceOptionsForProduct url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76/serviceOptionsForProduct.xml" />
<serviceOptionsByService url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76/serviceOptionsByService.xml" />
<productFeatures url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76/productFeatures.xml" />
 </ProductItem>

ฉันกำลังพยายามหาป้ายกำกับคำอธิบาย นี่คือโค้ดจาวาของฉัน

package com.ni.apps.elearningrest.client;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;


import javax.xml.bind.annotation.XmlElementWrapper;

@XmlRootElement(name = "ProductItem")
public class DescriptionDTO {

    private String description;
    private String uri;


    @XmlElement(name = "description")
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }               
}

แต่ฉันยังคงได้รับ "องค์ประกอบที่ไม่คาดคิด (uri: "http://providers.natinst.com/pdi-rest/1.0/meta/, local:"ProductItem") องค์ประกอบที่คาดหวังคือข้อผิดพลาด ‹{}ProductItem>" ฉันจะทำอย่างไรเพื่อแก้ไขปัญหานี้


person Nacho321    schedule 21.05.2012    source แหล่งที่มา


คำตอบ (2)


ลองเพิ่มเนมสเปซลงในคำอธิบายประกอบ JAXB:

@XmlRootElement(name = "ProductItem", namespace="http://providers.natinst.com/pdi-rest/1.0/meta/")

person hage    schedule 21.05.2012
comment
โอเค นั่นจัดการข้อผิดพลาดไปแล้ว แต่ตอนนี้ฉันไม่ได้รับคำอธิบาย มีความคิดอะไรบ้าง? - person Nacho321; 21.05.2012
comment
ตกลง แก้ไขแล้ว... ฉันยังเพิ่มเนมสเปซบน @XmlElement ด้วย ดูเหมือนว่า @XmlElement(name = description, namespace = htt p://providers.natinst.com/pdi-rest/1.0/meta/) ขอบคุณ! - person Nacho321; 21.05.2012

แม้ว่าคุณจะสามารถระบุคุณสมบัติเนมสเปซบนคำอธิบายประกอบ @XmlRootEleemnt และ @XmlElement ได้ แต่ฉันขอแนะนำให้ใช้ประโยชน์จากคำอธิบายประกอบ @XmlSchema เพื่อระบุเนมสเปซเริ่มต้นแทน

com/ni/apps/elearningrest/client/package-info.java

@XmlSchema( 
    namespace = "http://providers.natinst.com/pdi-rest/1.0/meta/", 
    elementFormDefault = XmlNsForm.QUALIFIED) 
package com.ni.apps.elearningrest.client;

สำหรับข้อมูลเพิ่มเติม

person bdoughan    schedule 21.05.2012