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]

Leave a Reply

Your email address will not be published.