Is there a way to add JSR303-annotations to cxf-generated classes?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 14:30:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!