An open API service indexing awesome lists of open source software.

https://github.com/krasa/krasa-jaxb-tools

XJC / JAXB plugin for generation of Bean Validation Annotations (JSR-303) and replacing primitive types
https://github.com/krasa/krasa-jaxb-tools

Last synced: over 1 year ago
JSON representation

XJC / JAXB plugin for generation of Bean Validation Annotations (JSR-303) and replacing primitive types

Awesome Lists containing this project

README

          

[![Maven Central](https://img.shields.io/maven-central/v/com.github.krasa/krasa-jaxb-tools.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.krasa/krasa-jaxb-tools/)

>NOTE: I no longer use and maintain this plugin. Consider using this fork: https://github.com/fillumina/krasa-jaxb-tools

Contains:
----------------
* plugin for replacing primitives **-XReplacePrimitives** (e.g. int -> Integer)
* plugin for generation of Bean Validation Annotations (JSR-303) **-XJsr303Annotations**

----

Release:
----------------
```xml

com.github.krasa
krasa-jaxb-tools
1.8

```
Very Old Snapshot:
----------------
```xml

com.github.krasa
krasa-jaxb-tools
1.7-SNAPSHOT

snapshots-repo
https://oss.sonatype.org/content/repositories/snapshots

false


true

```

----
XJsr303Annotations
----------------
Generates:
* @Valid annotation for all complex types, can be further restricted to generate only for types from defined schema: -XJsr303Annotations:targetNamespace=http://www.foo.com/bar
* @NotNull annotation for objects that has a MinOccur value >= 1 or for attributes with required use
* @Size for lists that have minOccurs > 1
* @Size if there is a maxLength or minLength or length restriction
* @DecimalMax for maxInclusive restriction
* @DecimalMin for minInclusive restriction
* @DecimalMax for maxExclusive restriction, enable new parameter (inclusive=false) with: -XJsr303Annotations:JSR_349=true
* @DecimalMin for minExclusive restriction, enable new parameter (inclusive=false) with: -XJsr303Annotations:JSR_349=true
* @Digits if there is a totalDigits or fractionDigits restriction.
* @Pattern if there is a Pattern restriction

----------------

@NotNull's default validation message is not always helpful, so it can be customized with **-XJsr303Annotations:notNullAnnotationsCustomMessages=OPTION** where **OPTION** is one of the following:
* `false` (default: no custom message -- not useful)
* `true` (message is present but equivalent to the default: **"{javax.validation.constraints.NotNull.message}"** -- not useful)
* `FieldName` (field name is prefixed to the default message: **"field {javax....message}"**)
* `ClassName` (class and field name are prefixed to the default message: **"Class.field {javax....message}"**)
* `other-non-empty-text` (arbitrary message, with substitutable, case-sensitive parameters `{ClassName}` and `{FieldName}`: **"Class {ClassName} field {FieldName} non-null"**)

----------------

Bean validation policy can be customized with **-XJsr303Annotations:generateServiceValidationAnnotations=OPTION** where **OPTION** is one of the following:
* `InOut` (default: validate requests and responses)
* `In` (validate only requests)
* `Out` (validate only responses)

**Using this option requires to specify krasa as front end generator** (See example below)

----
XReplacePrimitives
----------------
* replaces primitive types by Objects
* WARNING: must be defined before XhashCode or Xequals

----
Example project with tests:
----------------
https://github.com/krasa/krasa-jaxb-tools-example

----
Usage:
----------------
```xml

org.apache.cxf
cxf-codegen-plugin
${cxf-codegen-plugin.version}


wsdl2java
generate-sources



src/main/resources/wsdl/...

...
-xjc-XJsr303Annotations

-xjc-XJsr303Annotations:targetNamespace=http://www.foo.com/bar

-xjc-XJsr303Annotations:generateNotNullAnnotations=true

-xjc-XJsr303Annotations:notNullAnnotationsCustomMessages=false
-xjc-XJsr303Annotations:JSR_349=false
-xjc-XJsr303Annotations:verbose=false

-fe
krasa
-xjc-XJsr303Annotations:generateServiceValidationAnnotations=In





wsdl2java





com.github.krasa
krasa-jaxb-tools
${krasa-jaxb-tools.version}

...

```

```xml

org.jvnet.jaxb2.maven2
maven-jaxb2-plugin



generate


true



${basedir}/src/main/resources/wsdl

*.*


*.xs




true

-XJsr303Annotations



com.github.krasa
krasa-jaxb-tools
${krasa-jaxb-tools.version}




```

```xml

org.apache.cxf
cxf-xjc-plugin
2.6.0

${basedir}/src/generated/


true
src/main/resources/a.xsd
foo

-XJsr303Annotations
-XJsr303Annotations:targetNamespace=http://www.foo.com/bar




com.github.krasa:krasa-jaxb-tools:${krasa-jaxb-tools.version}




generate-sources
generate-sources

xsdtojava


```