Skip to content

binis2/code-generation-jackson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

126 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

code-generation-jackson

Jackson support module for Binis CodeGen Library.

Description

Set of helper classes to enable deserialization of object generated by Binis CodeGen library and trigger validations upon deserialization.

Web Requests

code-generation-spring-configuration and code-generation-jackson modules enable the usage of prototypes as web request objects simple and easy like this

@CodeRequest
public interface TestRequestPrototype {

    String name();
    String value();
    
}

and then you can simply use it.

    @PostMapping(value = "/test", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Result test(@RequestBody TestRequest request){
        ...
    }

Bean Validation

If we add code-generation-validation module into the mix and extend the example above with some validations and sanitizations.

@CodeRequest
public interface TestRequestPrototype {

    @ValidateNull
    @SanitizeTrim    
    @ValidateLength(min = 5, minMessage = "Name must be longer than 5 characters!")
    String name();

    @ValidateNull
    @SanitizeTrim
    String value();

    @ValidateLength(3)
    @ValidateRegEx(expression = "\\d+")
    String numbers();

    @JsonIgnore //Note: all other annotations works as well
    Long other();
}

upon calling our web method all of the fields validations and sanitizations will be performed automatically. If one or more validation fails, an exception (ValidationFormException) is raised. Inside the exception class you will find list of all the fields which validations failed along with list of all validations that were not satisfied for each field. Here is how the exception looks like in the evaluator

evaluator

For usage examples please see [https://github.com/binis2/code-generation]
For full project examples please see [https://github.com/binis2/code-generation-examples]

Maven Dependency

    <dependency>
        <groupId>dev.binis</groupId>
        <artifactId>code-generator-jackson</artifactId>
        <version>1.3.3</version>
    </dependency>

Other modules of the suite

Core - [https://github.com/binis2/code-generation-core]
Generation Module - [https://github.com/binis2/code-generation]
Spring Extension - [https://github.com/binis2/code-generation-spring]
Tests mocking suite - [https://github.com/binis2/code-generation-test]
Annotation processor - [https://github.com/binis2/code-generation-annotation]
Validation and Sanitization extension - [https://github.com/binis2/code-generation-validation]
Spring Boot configuration - [https://github.com/binis2/code-generation-spring-configuration]
Projections support - [https://github.com/binis2/code-generation-projection]
Hibernate support - [https://github.com/binis2/code-generation-hibernate]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors