Spring Boot JAXB unable to marshal type error


Working with a SOAP API with Spring Boot WS. I was getting the following error trying to create the request.

I was originally directly using the JAXB generated classes to form my requests:

The correct way is to use the provided JAXB ObjectFactory:

But to prevent marshalling errors you need to wrap your object in a JAXBElement object:

  1. Almost done (THANKS A LOT), however in my case, after received the response,
    I’m getting a ClassCastException, like following:

    Caused by: java.lang.ClassCastException: javax.xml.bind.JAXBElement cannot be cast to com.connector.RegistroResponse
    at hello.CountryClient.registro(RegistroClient.java:70) ~[main/:na]
    at hello.Application.lambda$lookup$0(Application.java:21) [main/:na]

  2. Not working. My WSDL was compiled using wsimport. And I tried the ObjectFactory suggestion above and I am still getting error below. Also, the cast suggestion is not correct since my ObjectFactory does not create a JAXBElement object..

    Caused by: com.sun.istack.internal.SAXException2: unable to marshal type “…” as an element because it is missing an @XmlRootElement annotation

  3. thanks worked for request, but for response i am getting
    java.lang.ClassCastException: javax.xml.bind.JAXBElement cannot be cast to

Leave a Reply

Your email address will not be published.