MOXy Schema generation of xsd:restictions [message #1707431] |
Fri, 04 September 2015 16:44 |
J F Messages: 256 Registered: July 2009 |
Senior Member |
|
|
MOXy BeanValidator gives me the ability to add validation to my JAXB classes.
Using Moxy's XJC "Bean Validation Plugin" I can generate Bean Validation in my generated JAXB classes based on Schema restrictions or facets.
However is there any way of generating a schema with restrictions based on a java class annotated with Bean Validation annotations?
XJC has a handy plugin architecture, but so far as I can see there is no 'Java first' equivalent which I can plugin into if I wish to enhance the generated XSD with additional restrictions or facets, or even to add XML comments. Where would I start if I wanted to add this functionality to MOXy? MOXy is extremely flexible with meet in the middle mappings, can this be used during schema generation?
The jaxb-facets code seems to do what I want but evidently this is aimed at the JAXB-RI and work in this area at least seems stalled according to this java.net JIRA. So in terms of tracking a spec I guess the simplest thing would be to support Java Bean Validation Annotations -> XSD facets as a mirror image of what Moxy already does XSD facets -> Java Bean Validation Annotations. Would the Eclipselink team be open to taking in an implementation of this for MOXy?
[Updated on: Mon, 07 September 2015 16:59] Report message to a moderator
|
|
|
|
|
|
|
Re: MOXy Schema generation of xsd:restictions [message #1707653 is a reply to message #1707647] |
Tue, 08 September 2015 11:46 |
J F Messages: 256 Registered: July 2009 |
Senior Member |
|
|
Look like this was fixed in master about 5 months ago.
Running the same example with 2.7.0-SNAPSHOT from https://oss.sonatype.org/content/repositories/snapshots/ gives the following output;
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="contactInfo5">
<xsd:sequence>
<xsd:element name="code">
<xsd:simpleType>
<xsd:restriction base="xsd:int">
<xsd:maxInclusive value="1000"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="phoneNumber" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ContactInfo5" type="contactInfo5"/>
</xsd:schema>
Also I had to annotate the java fields with @XmlElement before the facets were kicked into life. @XmlAttribute, @XmlAccessorType(XmlAccessType.FIELD) made no difference.
[Updated on: Tue, 08 September 2015 12:25] Report message to a moderator
|
|
|
|
Re: MOXy Schema generation of xsd:restictions [message #1707845 is a reply to message #1707667] |
Wed, 09 September 2015 16:34 |
Dmitry Kornilov Messages: 9 Registered: June 2014 |
Junior Member |
|
|
I see in the code that facets generation is invoked only on elements annotated with @XmlElement. Currently @XmlAttribute and @XmlAccessorType(XmlAccessType.FIELD) are not supported.
There is a handler for @Pattern annotation in the code. It's surprising that it doesn't work. I'll take a look at your code possibly this week and find out why it doesn't work.
[Updated on: Wed, 09 September 2015 16:37] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04169 seconds