问题
The title probably said it all, I was wondering if one could tell the cxf-codegen-plugin to add, for example, the xsd-patterns as @Pattern
annotations. Schema validation is nice and all, but sometimes I just want to check a single element and not endless myriads of xml lines.
Therefor I was wondering if there is a trick / option / dirty hack out there that would help me turning
<xs:simpleType name="string2000">
<xs:restriction base="xs:string">
<xs:maxLength value="2000"/>
<xs:minLength value="1"/>
<xs:pattern value="[\p{IsBasicLatin}\p{IsLatin-1Supplement}-[ \t\r\n]][\p{IsBasicLatin}\p{IsLatin-1Supplement}-[\t\r\n]]*"/>
</xs:restriction>
</xs:simpleType>
into
@Pattern(regexp = "\\p{IsBasicLatin}\\p{IsLatin-1Supplement}-[ \\t\\r\\n]][\\p{IsBasicLatin}\\p{IsLatin-1Supplement}-[\\t\\r\\n]]*")
@Size(min = 1, max = 2000)
since adding it manually is a no-go with this amount of xml, and it would really make things easier.
回答1:
I have no direct experience with the cxf-codegen-plugin but, I too had a need to include @Pattern
, @Size
, and other <xs:restriction />
annotations derived from XSDs into my JAXB generated classes and ended up using the krasa-jaxb-tool which does just this.
See Blaise Doughan's answer in including-xsrestrictions-as-annotations-in-moxy-generated-java-classes.
来源:https://stackoverflow.com/questions/12249366/is-there-a-way-to-add-jsr303-annotations-to-cxf-generated-classes