Is there an XML serialization framework for Java that does not use reflection, but instead generates static serialization code (Java source) from XSD ?
-
2I'm curious to know what the reason is if you don't mind sharing?Vadim– Vadim2012-01-23 09:52:25 +00:00Commented Jan 23, 2012 at 9:52
-
@laixer, sometimes reflection doesn't work, either by design or point in time limitations of the environment where one needs to run its code. Please take a look at this link, read all the way through, and you might get an idea. code.google.com/p/googleappengine/issues/detail?id=1267Petru Gardea– Petru Gardea2012-01-24 00:35:52 +00:00Commented Jan 24, 2012 at 0:35
-
@laixer Another use case might be Java ME, where Class.forName and Object.getClass() are all the reflection you've got.Martin Ellis– Martin Ellis2012-01-24 10:48:06 +00:00Commented Jan 24, 2012 at 10:48
1 Answer
I've never seen anything that does exactly what you are asking for: generating serialization code from XSD. However, if you're not stuck with an existing XSD schema, Modello may satisfy your requirements.
Modello is used by Maven for parsing pom.xml and settings.xml files. It reads a .mdo file (like this description of the Maven project model), and can generate a Java object model; an XML Schema (XSD) file; and serialisation/de-serialisation code. The serialisation/deserialisation code can use one of a number of XML parser APIs (e.g. JDOM, StAX, etc.). The XML parser API used by Maven itself is xpp3.
Modello can also generate code to convert one version of the model to another. It can generate HTML documentation about your XML format.
If you have an existing XSD, it might be too much work to use modello. But, if you're creating your own XML format, it could be worth starting with modello and generating the XSD.