jaxb冒号节点返回null

chhkpiq4  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(175)

我使用jaxbforxml-to-java对象和子节点返回空值xml代码是

xmlns:tns="http://www.xxxxxx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.xxxxxxx xxxx.xsd"
    xmlns:ns0="http://www.xxxxx.com/xxxx/event/Common/EventCommon">
    <eventCommon>
        <ns0:application>xxxxx</ns0:application>
        <ns0:companyId>xxxxxx</ns0:companyId>
        <ns0:operator>xxxxxx</ns0:operator>
        <ns0:today>xxxxxx</ns0:today>
        <ns0:transactionStage>xxxxx</ns0:transactionStage>
        <ns0:eventId>xxxxxxx</ns0:eventId>
        <ns0:creationTime>2020-11-18T08:19:26.394</ns0:creationTime>
        <ns0:customCommon name="xxxx" />
    </eventCommon>```

        Created java POJO when Unmarshaller getting null on eventCommon tag
root node ExternalUserFlow.java
    ```

    @XmlRootElement(name = "ExternalUserFlow")
            public class ExternalUserFlow {
            @XmlElement(name = "eventCommon")
            EventCommon EventCommonObject;
            // Getter Methods 

            public EventCommon getEventCommon() {
            return EventCommonObject;
            }
            // Setter Methods 

            public void setEventCommon(EventCommon eventCommonObject) {
            this.EventCommonObject = eventCommonObject;
            }

            @Override
            public String toString()
            {
               return "ExternalUserFlow [EventCommonObject = "+EventCommonObject+"]";

            }
            }

子节点java类

package xxx.com.pojo;

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

    @XmlRootElement(name = "eventCommon")
    public class EventCommon {

         Operator OperatorObject;
         Today TodayObject;

         // Getter Methods 

         @XmlElement(name="ns0:operator")
         public Operator getOperator() {
          return OperatorObject;
         }

         @XmlElement(name="ns0:today")
         public Today getToday() {
          return TodayObject;
         }

        // setter method
         @Override
            public String toString()
            {
                return "EventCommon[Operator = "+Operator +", Today = "+Today +"]";
            }

        }

//用于解组代码的java main

public class XMLtoObject {

        public static void main(String args[]) throws XMLStreamException, IOException, SOAPException {

    File xmlFile = new File("Userxml.xml");
    JAXBContext jaxbContext;
    try
    {

                  System.out.println("inside"); jaxbContext =
                  JAXBContext.newInstance(ExternalUserFlow.class);
                  Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
                  ExternalUserFlow user = (ExternalUserFlow)
                  jaxbUnmarshaller.unmarshal(xmlFile);
                  System.out.println(user);

    }
    catch (JAXBException e) 
    {
        e.printStackTrace();
    }
    }
    }

已将架构位置添加到package.info中

@javax.xml.bind.annotation.XmlSchema (               
            xmlns = { 
                    @javax.xml.bind.annotation.XmlNs(prefix = "tns", 
                             namespaceURI="http://xxxxxxxx/ExternalUserFlow"),

                    @javax.xml.bind.annotation.XmlNs( prefix = "xsi",
                             namespaceURI="http://www.w3.org/2001/XMLSchema-instance"),

                    @javax.xml.bind.annotation.XmlNs( prefix = "ns0",
                             namespaceURI="http://xxxxxxx/Common/EventCommon"),             
                   },    
            location = "http://xxxxxxxxxx ExternalUserFlow.xsd",
            elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED        
        )

    package xxx.com.pojo;

有人能告诉我值为空的原因吗?
请注意:1。我是jaxb的新手。我正在使用eclipseide。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题