https://github.com/adorsys/beanval2json
Converts beanvalidation-annotations to JSON
https://github.com/adorsys/beanval2json
Last synced: 3 months ago
JSON representation
Converts beanvalidation-annotations to JSON
- Host: GitHub
- URL: https://github.com/adorsys/beanval2json
- Owner: adorsys
- License: apache-2.0
- Created: 2014-03-16T18:58:18.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-18T08:26:00.000Z (over 10 years ago)
- Last Synced: 2025-06-02T00:34:53.567Z (4 months ago)
- Language: Java
- Homepage:
- Size: 223 KB
- Stars: 5
- Watchers: 10
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# beanval2json
Converts [beanvalidation-annotations](http://beanvalidation.org) to JSON to be used for client-side validation.
This class:
package de.adorsys.beanval2json.test.model;
public class Person implements Serializable {@Pattern(regexp = "[a-zA-Z]+", message = "Please enter only letters")
private String name;
@Min(value = 500)
@Max(value = 5000)
private BigDecimal salary;
}
will be converted to:{
"de.adorsys.beanval2json.test.model.Person.name": {
"pattern": {
"regexp": "[a-zA-Z]+",
"message": "Please enter only letters"
}
},
"de.adorsys.beanval2json.test.model.Person.salary": {
"min": {
"value": "500"
},
"max": {
"value": "5000"
}
}
}A working example can be found in the [beanval2json-generator-test module](beanval2json-generator-test).
## Setup
Use the `de.adorsys.beanval2json.BeanvalAnnotationProcessor` e.g. via Maven:
maven-compiler-plugin
3.1
1.7
1.7
UTF-8
-proc:none
org.bsc.maven
maven-processor-plugin
2.2.4
process
process
generate-sources
de.adorsys.beanval2json.BeanvalAnnotationProcessor
${project.build.directory}/${project.build.finalName}/js
mapping.properties
messages.properties
ignore.txt
de.adorsys.beanval2json
beanval2json-generator
1.0.0-SNAPSHOT
## Options
* **mappingFile:** Path to a properties-file with full-qualified property-names as key. The annotation-processor uses the full qualified names
as key in the generated JSON-Object. The crux of the matter is how to map the values to the input-fields. One way could be to use e.g.
the input-ids and overwrite the mapping in this property-file.
* **messagesFile:** Path to a properties-file with error-messages. If the messages defined in the annotations start and end with a curley bracket
like {javax.validation.constraints.NotNull.message} the processor will use the defined message from this file.
* **ignoreFile:** Path to a line-separted file with Classes or Properties which should not be converted to JSON.## Validation
Beanval2Json converts beanvalidation values to JSON to be used for client-side validation. This project does no validation.
Most projects have their validation-plugins anyway which could use the generated JSON.
You can find a [html5-validation example](beanval2json-generator-test/src/main/webapp/html5-validation) and an [AngularJS example](beanval2json-generator-test/src/main/webapp/angular-js-validation) in the test-project.