Hi,
I have a RESTeasy driven REST API and would like to be able to return an
error message whenever an invalid value for a boolean element is received.
For instance, given the following type:
<xs:complexType name="aType">
<xs:complexContent>
<xs:element name="aBoolean" type="xs:boolean" minOccurs="1"
maxOccurs="1" />
</xs:complexContent>
</xs:complexType>
When receiving the following message body:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<aTypeid="1">
<aBoolean>nonsense</aBoolean>
</aType>
If the value of aBoolean is not one of either true or false i would like to
be able to return an error message stating that the value of the boolean
element isn't valid.
To do this i've tried adding a data converter for boolean types. Something
along the lines of:
<xs:annotation>
<xs:appinfo>
<jaxb:bindings
node="/xs:schema/xs:complexType[@name='aType']/xs:complexContent/xs:element[@name='aBoolean']">
<jaxb:property>
<jaxb:baseType>
<jaxb:javaType name="boolean"
parseMethod="net.my.converter.BooleanConverter.parseBoolean"/>
</jaxb:baseType>
</jaxb:property>
</jaxb:bindings>
</xs:appinfo>
</xs:annotation>
This seems ok except for the fact that in the generated class the type of
'aBoolean' has changed from being the primitive boolean to the class
Boolean. This means that upon creation of an instance of AType, ABoolean has
a null value and the method call isABoolean() can return null.
This change from the primitive boolean to the class Boolean fundamentally
changes the behaviour of the generated methods.
Is my approach the best way of validating element values that are mapped to
a primitive? If so, what should i do about the change of type in the
generated classes?
Thanks for your help,
Tim
--
View this message in context: http://old.nabble.com/Validation-of-boolean-values-and-javaType-tp30930053p30930053.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.