How can i convert java object to xml? I am trying to convert an incoming java object to xml in spring integration with a converter bean. is there another way than marshalling in Jaxb ? like using @TypeConverter. Or implementing converter class.
I’m not familiar with
@TypeConverter, but looks that that is an EclipseLink feature for JPA. In the end it has this JavaDoc on the
/** * Constant name for the reserved XML converter. * This will use JAXB to convert the object to and from XML. */ public static final String XML = "xml";
So, it still would require from you a JaxB
Marshaller to be configured.
Not sure from here why do you ask about Spring Integration if your end goal is JPA…
Anyway: the best way to convert object to XML in Spring Integration is indeed use a
MarshallingTransformer which could be configured with any
org.springframework.oxm.Marshaller impl, not only JaxB.
If you are looking for some conversion way in between, you may also look into
MappingJackson2MessageConverter when you inject an
XmlMapper from Jackson lib.
For better assisting you, we definitely need to know more about your use-case and what and how you’d like to marshal into an XML.