Sign in to follow this  

[java] Auto-generate XML schema/mapping/serialization code?

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I did some SOAP web server stuff a while ago, I found libraries existed for C++ which let you create a C++ class, and it would generate WSDL schema and code to read from a received XML message into objects of the class, etc. I want to have configuration files for a Java project but writing an XML loader is about the most tedious coding task I've ever had to do. Is there anything which would read a Java class definition and generate an XSD file, plus Java classes to allow me to read an object from XML? It sounds like the kind of thing that should be out there somewhere but I don't really know what to search for. Thanks for any tips.

Share this post


Link to post
Share on other sites
If you don't mind writing the code yourself you can use the reflection API to write some generic code which accepts a Class and some xml and converts it into a loaded object. Iterating over all the members and finding their associated xml attribute isn't that hard and works very well. I use this method for my data-driven xml stuff.

If you really wanted to go with generated code rather than a reusable runtime method, then you could use the reflection api to avoid parsing the class yourself.

HTH

Share this post


Link to post
Share on other sites
I highly recommend xstream. (http://xstream.codehaus.org/)

It uses java's reflection to automagically map XML to objects and back. Not the best for an enterprise solution but works well for simple data exchange/serialization.

Share this post


Link to post
Share on other sites

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this