0

I found this post earlier today about whether to XSD --> POJO or POJO --> to XSD.

Java to XSD or XSD to Java

It made us question whether we should even bother with making XSDs in our scenario. We assumed we should write XSD then generate Java POJOs from it, and then use those POJOs to transfer data between our REST server and clients. But what value do those XSDs have if we could just directly write the POJOs with the required annotations?

We thought it might help to write a custom XSD GUI tool instead of hand coding the XSD and that could be one benefit of having XSD. But I assume there are also GUI tools for creating JAXB beans?

Is it worth having XSD at the cost of the extra project complexity of having them and needing to generate the classes before compile time in our scenario?

Community
  • 1
  • 1
medloh
  • 941
  • 12
  • 33
  • Thanks for the opinions, I just wanted some assurance that we weren't heading down a bad path by defining our data transfer objects in XSD, and wasting our time and effort doing so. I've upvoted both answers, but I guess there really isn't a right answer to this question without knowing the exact details of a project. – medloh Sep 17 '14 at 21:09

2 Answers2

2

One benefit of an XML Scheme over a set of JAXB-annotated classes would be that you have a definition for "foreign" communication partners. Maybe you don't need it now, but what about tomorrow?

Another good reason of using XML Schema is that (if used wisely) restricts your types to what is easily (un)marshalled. It's possible to create POJO classes that are darned hard to serialize.

The third reason iÍ can think of is that you don't have to learn how to cope with all of those javax.xml.annotation annotation classes. It may be that you feel more familiar with them (and they may even permit you to do a trick or two over the XML Schema approach) but I've usually found it more convenient to write an XML Schema and watch xjc to handle the nitty-gritty details for me.

laune
  • 31,114
  • 3
  • 29
  • 42
1

It depends on your requirements. In some cases the requirements (of request/response maybe) are defined by the means of a XSD document as xsd can provide all the information(datatype etc) we need to build the classes, in these cases direct generation of POJO is helpful as we already have an xsd in place.

It might be a overhead for your case, if you have to first write an xsd and then generate an POJO object from it.

See what suits you, Choose wisely!

Vihar
  • 3,626
  • 2
  • 24
  • 47