简体   繁体   中英

Generate XSD from POJO (without JAXB)?

I need to create an XSD from some POJOs, most of which do not have a no-arg constructor. JAXB requires a no-arg constructor, hence my exclusion of JAXB from consideration. I don't own the code to the POJOs, so I can't go retrofit them (which also means I can't add any annotations).

Outside of rolling my own XSD generator via reflection introspection, is there some other method for generating XSDs from POJOs? You'd think the googles would reveal lots of tools, but so far my search skills haven't come up with anything. Every plugin/tool seems to use JAXB.

look at this tool see if it will do what you want: http://80.127.98.91:6060/internal/doc/ssj/devguide_java2schema.html

Sorry in a hurry, but there used to be a java2wsdl tool built under the apache axis project that would generate wsdl, which includes the xsd for the objects used by the interface. There may be something there to look for. It used to work really well.

this may be a better tool: http://xmlbeans.apache.org/ got to run.. hope this helps.

Take a look to Axis2 tools maybe it's not using JAXB but standard constructor with no-org maybe needed. http://axis.apache.org/axis2/java/core/tools/index.html

I think that's not a big deal to add no-arg constuctor to your classes.

Anothor way with standard JAXB tools : https://docs.oracle.com/javase/tutorial/jaxb/intro/j2schema.html Part "j2s-xmlType Example" :

A class must have either a public zero-argument constructor or a static zero-argument factory method in order to be mapped by this annotation. One of these methods is used during unmarshalling to create an instance of the class. The factory method can be located within in a factory class or the existing class.

There is an order of precedence as to which method is used for unmarshalling:

If a factory class is identified in the annotation, a corresponding factory method in that class must also be identified, and that method will be used. If a factory method is identified in the annotation but no factory class is identified, the factory method must be located in the current class. The factory method is used even if there is a public zero argument constructor method present. If no factory method is identified in the annotation, the class must contain a public zero argument constructor method

So you can create factories.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM