Adeel Asghar
Adeel Asghar

Reputation: 359

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"arg0"). Expected elements are <{}customerInfo>

I am facing this issue for 2 days but couldn't able to resolve this. I am trying to call a webservice using JAX-WS. Service call but the object in that is not parsed.

            JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
            factory.setServiceClass(ICustomer.class);
            factory.setAddress("http://localhost:8080/backend/services/CustomerInfo");
            ICustomer client = (ICustomer) factory.create();

            // Below is the service call. where 'object' is my CustomerInfo object/data
            client.saveCustomer(object);

Service Implementation Class:

@WebService(endpointInterface = "com.dev.backend.services.interfaces.ICustomer", serviceName="CustomerInfo")
public class ICustomerImpl implements ICustomer {

public boolean saveCustomer(Object object) {
    JAXBContext payloadContext;
    try {
        payloadContext = JAXBContext.newInstance(CustomerInfo.class);
        CustomerInfo o = (CustomerInfo)payloadContext.createUnmarshaller().unmarshal((Node)object); // Line 'error'
    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

(CustomerInfo)payloadContext.createUnmarshaller().unmarshal((Node)object) is the line where exception throw "javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"arg0"). Expected elements are <{}customerInfo>"

Can any please help me. I am looking for solution for 2 days.

Thanks

Upvotes: 1

Views: 1260

Answers (1)

Mithilesh Naik
Mithilesh Naik

Reputation: 21

Do you have an XML node like this?

<ws:customerInfo> ... </ws:customerInfo>

If you do, try removing "ws"

UPDATE: If you have a method similar to this:

public ReturnType Method1(
            @WebParam(name="RequestType1") RequestType1 request)

Try changing this to:

public ReturnType Method1(
                @WebParam(name="requestType1") RequestType1 request)

Note that, webParam name is different in both cases. RequestType1 is a class and name of the webParam is also same. The name parameter is like an instance name and is misunderstood with the class name if both are same.

Upvotes: 0

Related Questions