Reputation: 19
How can I transform a Java object into a different Java object based off of an XSD schema?
Upvotes: 1
Views: 221
Reputation: 111611
Asking for recommendations for specific tools/libraries is off topic on Stack Overflow.
In terms of tool categories, though, there are tools such as JAXB that will create Java classes for you based on an XSD. You might use such tools in one of two ways to solve your problem.
You could convert your source XSD and your target XSD into source and target Java classes, and then you could write Java code to convert objects of the source class to objects of the target class.
The advantage of this approach is that it can be done in Java without having to write a transformation in another language. The disadvantage is that for complex transformations, procedural Java can become unwieldy, and mapping everything can be tedious.
An alternative would be to marshal the source Java object into XML, and write an XSLT transformation of the source XML into the target XML. You could then unmarshal the target XML to an object of the target Java class.
The advantage of this approach is that XSLT gracefully handles both simple and complex transformations. The disadvantage is that adding XSLT to the mix may complicate the tool chain and/or require learning a new language if you're not already fluent in XSLT.
Upvotes: 1