dev-resources.site
for different kinds of informations.
Apache Camel #4 - Bean Validation
Published at
8/25/2019
Categories
java
apache
camel
apachecamel
Author
djoleb
Author
6 person written this
djoleb
open
There is a lot of cases where we needed to write validation for data input. This "problem" can be easily solved in Camel by using Bean Validation component.
Imagine we have a JSON input in our route and we want to validate payload.
{ "name":"Jane Doe", "cardNumber":"377198642272436", "email":"[email protected]", "paid":true, "price":1.25 }
To do that, we first we must unmarshall that payload to POJO.
But first, we must create a class with the same parameters as JSON and add Hibernate Validation annotations.
@NotNull
@Length(min = 1, max = 60)
private String name;
@CreditCardNumber
private String cardNumber;
@Email
private String email;
@NotNull
private boolean paid;
@Min(0.1)
private int price;
And then we add this to our Camel route.
//define a datasource for the class you want to validate. GsonDataSource dataSource = new GsonDatasource(JsonDto.class); //unmarshal JSON to POJO .unmarshall(dataSource) //Validate data .to("bean-validator:someLabelHere)
When that unmarshalled data is sent to bean validator, that objects will be validated by annotations we set for JsonDto fields.
Thank you for your attention.
apachecamel Article's
12 articles in total
Apache Camel - The Integration Framework for Modern Applications
read article
Introduction to Apache Camel K: Solving Integration Challenges
read article
Telegram bot with Camel & Spring boot
read article
Hello Mule (Mulesoft)
read article
Apache Camel 4.x + Spring Boot 3.x + RabbitMq + IbmMq
read article
Keeping Your Services Running Smoothly: A Guide to Java and Kubernetes Maintenance
read article
DLQ Integration Patterns: A high-level Comparison of Apache Camel and Spring Boot
read article
Apache Camel or workflows or both?
read article
Apache Camel #4 - Bean Validation
currently reading
Apache Camel #2 - Calling Rest API
read article
Apache Camel #1 - Introduction to Apache Camel
read article
GETTING CAMEL - CAMEL in Action
read article
Featured ones: