I’ve got following code to perform XSLT transformation from one JAXB annotated object to another JAXB annotated object. Is the performance going to be really poor in this case? Does it marshall JAXB object to XML, transform it to another XML and unmarshall, or are there any better tricks here?
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(new StreamSource(mapping.getInputStream()));
JAXBResult result = new JAXBResult(JaxbUtils.getJAXBContext(CalypsoUploadDocument.class));
transformer.transform(new JAXBSource(JaxbUtils.getJAXBContext(CalypsoUploadDocument.class), uploadMessage),result);
return result.getResult();
If using Java 6 (my production experience is based on the Oracle JDK) this is a valid approach we also have done. Performance is quite good. A minor improvement is to use a Templates instance.
On the other hand I do not recommend this approach if your application has one or just a few transformations and the transformations itself will not change over time. Then a direct approach is much faster (java instance -> java mapping -> java instance)