1

Working on a large integration project where we are also doing validation on some of the data which we are integrating back and forth.

We are using the CXF-XJC-plugin to generate java classes from XSD and WSDL files. It would be very keen to have restrictions added as part of the generated classes, rather than having plain POJO classes.

An example would be:

<xsd:element name="someString" minOccurs="0">
   <xsd:simpleType>
      <xsd:restriction base="xsd:string">
         <xsd:maxLength value="12"/>
      </xsd:restriction>
   </xsd:simpleType>
</xsd:element>

Currently create as:

String someString;

Basic setter and getter and the fancy fluent api, but nowhere is any restriction logic about the 12 characters

Anyone would know how to generate with restrictions built in?

Wisienkas
  • 1,602
  • 2
  • 17
  • 22
  • Possible duplicate of https://stackoverflow.com/questions/13775465/does-jaxb-support-xsdrestriction – Piotr Wilkin Nov 17 '17 at 14:06
  • Ah yes, Hope this question will lead more to the other than, since I was not able to find it. – Wisienkas Nov 17 '17 at 14:35
  • Maybe this is interesting for you: you can [validate objects in memory against the XSD](http://blog.bdoughan.com/2010/11/validate-jaxb-object-model-with-xml.html) - so that way you can check the constraints without marshalling them. – Jesper Nov 17 '17 at 15:06

1 Answers1

2

You can specify a separate bindings file, which contains the enableFailFastCheck attribute:

<?xml version="1.0" encoding="UTF-8"?>
<globalBindings xmlns="http://java.sun.com/xml/ns/jaxb" enableFailFastCheck="true"/>
VGR
  • 40,506
  • 4
  • 48
  • 63