I first explain my real problem.
I have a XML and the relative XML schema (an XSD). I want to transform it in JSON. XML and its schema can change, so I have to do it at runtime.
Now, the XSD can be a very complex type. I know that exists libraries that transform XML to JSON directly, but I don't think they will work well with complicated structures.
My intention was to use Jackson, my favorite JSON library. But Jackson needs a Java class and a Java object to serialize the object as JSON.
So I thought about JAXB. With JAXB I can create a .java from a XML schema.
After that, I can load the class at runtime and, with JAXB, create an instance of the class using the XML. Then Jackson.
The problem is I have not found a single example, and I didn't find nothing in JAXB API docs too, of how to use JAXB to convert a XML schema to a java class using its API. All examples suggest to use external programs to generate the classes. I don't want to do this, since IMHO it's less portable.
Is there not a way to use JAXB, or another Java library, to convert an XML schema to a .java class using Java code and not an external tool?
Alternatively, is there not a way to convert XML to JSON, using the XML schema as source of its structure?
PS: I'm using Java Azul ZuluFx 8. I don't think it's relevant, but you never know.