I am trying to unmarshal java objects to xml in Spring integration using UnmarshallingTransformer but I am getting an error that the payload is not created. This is my code :
@Bean
public Marshaller jaxbMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClassesToBeBound(TargetedClass.class);
return jaxb2Marshaller;
}
@Bean
public IntegrationFlow posting() {
try {
return IntegrationFlows.from(Http.inboundGateway("/foo")
.requestMapping(m -> m.methods(HttpMethod.POST)
).errorChannel("error.input")
)
.transform(Transformers.objectToString())
.enrichHeaders(h -> h.headerExpression())
.transform(httpcallFunc())
.transform(new UnmarshallingTransformer((Unmarshaller) jaxbMarshaller()))
.get();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}
I am getting this error back.
org.springframework.messaging.MessagingException: failed to create Source for payload type [com.org.model.ClassName]
org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 : "<Map><timestamp>2022-03-18T11:24:26.568+00:00</timestamp><status>500</status><error>Internal Server Error</error><path>/foo</path></Map>"
This occurs when I am trying to use the UnmarshallingTransformer.