Skip to main content

JAXB Exception --javax.xml.bind.UnmarshalException

6 replies [Last post]
vedprakash99
Offline
Joined: 2007-12-06

Hi All,
I am trying to create a java object from the XML which i have it. i am working on Java 1.5....12

STEPS followed are:-

1. i have taken a WSDL file for generating the Java classes
2. then i created a client program and written the below code
3. i had taken an xml file which i have passed it to the below mentioned code.

----- XML file which is been used --------
<?xml version="1.0" encoding="UTF-8"?>

TRS

DSL-L2

----- WSDL is been used for generation the structure of bean objects ------

---Client code ----
JAXBContext jc = JAXBContext.newInstance( "au.com.powertel.powerlink.xsd" );

Unmarshaller unmarshaller = jc.createUnmarshaller() ;

FileInputStream f=new FileInputStream("D:\\Shared Files\\Powertel\\QualifyExchangeRequest.xml");

System.out.println("Completed the import of the file");

QualifyExchangeRequest sqresp = (QualifyExchangeRequest)unmarshaller.unmarshal(f) ;

System.out.println("Exchange code value received from the file is ---" +sqresp.getProductType());

------ Exception Received -----

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"QualifyExchangeRequest"). Expected elements are <{http://www.powertel.com.au/PowerLink/xsd}CancelServiceRequest>,<{http://www.powertel.com.au/PowerLink/xsd}CancelServiceResponse>,<{http://www.powertel.com.au/PowerLink/xsd}CreateServiceTicketRequest>,<{http://www.powertel.com.au/PowerLink/xsd}CreateServiceTicketResponse>,<{http://www.powertel.com.au/PowerLink/xsd}DSLAssureServiceRequest>,<{http://www.powertel.com.au/PowerLink/xsd}DSLAssureServiceResponse>,<{http://www.powertel.com.au/PowerLink/xsd}DSLEnquireServiceRequest>,<{http://www.powertel.com.au/PowerLink/xsd}DSLEnquireServiceResponse>,<{http://www.powertel.com.au/PowerLink/xsd}DSLNewServiceRequest>,<{

Can you please help me out in this

i need information urgently please.....

thanks and regards
Ved prakash

you can contact me directly at vedprakash.99@gmail.com

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sumit007
Offline
Joined: 2008-02-04

hi,
i am getting Type mismatch: cannot convert XmlAccessType to AccessType error in one of my java class.
Code is:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getSmsDeliveryStatusResponse", propOrder = {
"result"
})
please tell me how you removed this error.
Thanks in advance.

tigera
Offline
Joined: 2007-07-15

According to that error message, the XML file is not validating the schema - would you mind posting the entire output of the error? I can't tell whether JAXB is giving you a faulty error message or a legitimate one.

vedprakash99
Offline
Joined: 2007-12-06

Hi,
Thanks for your reply... you where correct the xml file was not correct with respect to the schema.. there was a fault in the namespace.

But now i am stucked with some other problem :- can you please help me in this

error now says that
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from AccessType to XmlAccessType

at au.com.powertel.powerlink.xsd.QualifyExchangeRequest.(QualifyExchangeRequest.java:39)
at au.com.powertel.powerlink.client.JXBClient.main(JXBClient.java:62)

even if i try simple examples it gives me the same error...

thanks
ved prakash

vedprakash99
Offline
Joined: 2007-12-06

hi,
This Problem of convert from AccessType to XmlAccessType is solved...

can any one tell me about the error during unmarshalling.... while i create an Jaxb context and use that JaxbContext instance for creating a Unmarshall ... it gives me an error....... telling that we have duplicate elemets......

------- Actual error ------------------

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "length"
this problem is related to the following location:
at public int au.com.powertel.powerlink.xsd.BridgeTap.getLength()
at au.com.powertel.powerlink.xsd.BridgeTap
at protected java.util.List au.com.powertel.powerlink.xsd.ULLCable.bridgeTap
at au.com.powertel.powerlink.xsd.ULLCable
at protected au.com.powertel.powerlink.xsd.ULLCable au.com.powertel.powerlink.xsd.DSLQualifyServiceResponse.cableDetails
at au.com.powertel.powerlink.xsd.DSLQualifyServiceResponse
at public au.com.powertel.powerlink.xsd.DSLQualifyServiceResponse au.com.powertel.powerlink.xsd.ObjectFactory.createDSLQualifyServiceResponse()
at au.com.powertel.powerlink.xsd.ObjectFactory
this problem is related to the following location:
at protected int au.com.powertel.powerlink.xsd.BridgeTap.length
at au.com.powertel.powerlink.xsd.BridgeTap
at protected java.util.List au.com.powertel.powerlink.xsd.ULLCable.bridgeTap
at au.com.powertel.powerlink.xsd.ULLCable
at protected au.com.powertel.powerlink.xsd.ULLCable au.com.powertel.powerlink.xsd.DSLQualifyServiceResponse.cableDetails
at au.com.powertel.powerlink.xsd.DSLQualifyServiceResponse
at public au.com.powertel.powerlink.xsd.DSLQualifyServiceResponse au.com.powertel.powerlink.xsd.ObjectFactory.createDSLQualifyServiceResponse()
at au.com.powertel.powerlink.xsd.ObjectFactory

at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:330)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:198)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:286)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:358)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:323)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
at au.com.powertel.powerlink.client.JXBClient.main(JXBClient.java:23)
so please do needful

thanks,
ved prakash

tigera
Offline
Joined: 2007-07-15

Annotate the getLength method rather than the length field and the error should go away.

vedprakash99
Offline
Joined: 2007-12-06

hi Tigera,
Greetings! Thanks for the support you are providing to me.....

hey even the sample programs in my system also doesnt work ..... can you tell me whats is the reason for that ... i will be attaching the files with the class path information in this......

i think this error should be because i am trying to do something wrong .... so can u tell me where i am doing wrong with the help of the attached files please.....

thanks

ved prakash...