无法解组JAXBElement结构。结果为空

时间:2016-03-21 16:45:59

标签: java jaxb

我有像

这样的xml结构
    <SyncContact>
            <Contact>
                <Addresses>
                    <Entry>
                        <AddressType>
                            <Code>reg</Code>
                        </AddressType>
                    </Entry>
               <Addresses>
          <Contact>
 </SyncContact>

和classe一样:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SyncContact",  propOrder = {
    "Contact",
})
@XmlRootElement(name = "synContact ")
public class SynContact {

    @XmlElementRef(name = "Contact", type = JAXBElement.class, required = false)
    protected JAXBElement<Contact> abContact;

    public JAXBElement<Contact> getContact() {
        return abContact;
    }

    public void setContact(JAXBElement<Contact> value) {
        this.Contact = value;
    }

}

以上课程中使用的其他课程:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Contact", propOrder = {
    "Addresses",}
public class ABContact {
@XmlElementRef(name = "Addresses", type = JAXBElement.class, required = false)
    protected JAXBElement<Contact.Addresses> Addresses;

 public JAXBElement<Contact.Addresses> getAllAddresses() {
        return Addresses;
    }


    public void setAllAddresses(JAXBElement<Contact.Addresses> value) {
        this.Addresses = value;
    }
}

以及上面使用的其他类:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "entry"
})
public static class Addresses {
 public List<ABContact.Addresses.Entry> getEntry() {
        if (entry == null) {
            entry = new ArrayList<Contact.Addresses.Entry>();
        }
        return this.entry;
    }

}

我解密的代码:

 private static SyncContact createContact(String contactRequestESB) {

            SyncContact contactSyncObj = null;
            JAXBContext jaxbContext = null;
            SyncContact contactSynchronisation = null;
            File file = new File(contactRequestESB);

            try {

                JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class);

                Unmarshaller u = jc.createUnmarshaller();

                File f = new File (contactRequestESB);

                jaxbContext = JAXBContext.newInstance(SyncContact.class);
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
                JAXBElement<SyncContact> root = (JAXBElement<SyncContact>)jaxbUnmarshaller.unmarshal(file);
                contactSyncObj = root.getValue();

            } catch (Exception e) {
                e.printStackTrace();
            }
            return contactSyncObj;
        }

但是当我调试我的unmarshal时,我看到我的条目没有被解组。我无法理解为什么它不能这样做。我有SyncContact里面我有联系方式联系我已经解决但是我的xml没有条目值(reg)。 请帮忙。

0 个答案:

没有答案