JAXB 2 annotation and XSD

In the JAXB 1.0 era, the recommended way to work with the java object, XSD and XML is to start by defining XSD, use JAXB to create Java classes from XSD and support XSD.

But now with JAXB 2.0 annotations, it’s very convenient to create XSD from Java classes. Is it recommended to start with Java classes and annotations and generate XSD?

Thanks,

+4
source share
2 answers

I recommend that developers start with the object model and annotate it to get the desired XML. This gives you more flexibility when building your application (for example, also mapping a database using JPA). You only need to create an XML schema if you want to split the structure (for example, as part of the WSDL).

Check out my block for JAXB examples, starting with model classes:

+2
source

I would not say so, no. An XML schema is much richer in terms of types and defined structures, so any schema you create from Java will be quite simple and expressionless.

In all cases, generate the source schema from your code, but then you should really embellish the result and save it as a first-class citizen, not a generated product. After it is created, you can connect it back to the JAXB / unmarshaller marker as a verification level.

+1
source

Source: https://habr.com/ru/post/1332824/


All Articles