Exception in thread “main” javax.xml.bind.MarshalException

4.13K viewsExceptionErrorJava
0

Exception in thread “main” javax.xml.bind.MarshalException
– with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type “org.datacontract.schemas._2004._07.radixx_connectpoint_security.RetrieveSecurityToken” as an element because it is missing an @XmlRootElement annotation] at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:311)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:116)
at com.util.JAXBUtil.Marshall(JAXBUtil.java:23)
at com.test.Test.main(Test.java:19)
Caused by: com.sun.istack.internal.SAXException2: unable to marshal type “org.datacontract.schemas._2004._07.radixx_connectpoint_security.RetrieveSecurityToken” as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:234)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:323)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:479)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:308)
… 4 more

Manohar Changed status to publish July 30, 2019
Add a Comment
2

Please add @XmlRootElement(name = “here mention the name of the root tag”)

For Example :

XML  :

<SecurityToken>
<Code>12563</Code>
<Source>21545</Source>
<SecurityToken>

Code :

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SecurityToken", namespace = "http://schemas.datacontract.org/2004/07/", propOrder = {
    "Code",
    "Source"
})
@XmlRootElement(name = "SecurityToken")
public class SecurityToken
   
{
     @XmlElement(name = "Code", required = true, nillable = true)
    protected String code;
    @XmlElement(name = "Source", required = true, nillable = true)
    protected String source;

 //here some code

}

Try this ,i hope it will work.

 

 

Manohar Changed status to publish July 30, 2019
Add a Comment
Write your answer.