camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Huston <>
Subject RE: Camel REST Spring Boot Pojo Mandatory Json Properties
Date Tue, 12 Dec 2017 18:33:33 GMT
I don't have a REST-specific example to show you, but in other scenarios I've done, after unmarshalling
to POJO:


If the validator annotations find a violation an exception will be thrown.


> -----Original Message-----
> From: Richard James []
> Sent: Tuesday, December 12, 2017 1:19 PM
> To:
> Subject: Camel REST Spring Boot Pojo Mandatory Json Properties
> Hi,
> I am in the process of implementing a REST Api using Spring boot and Camel.
> This is up and running and works well.
> What I am currently trying to enforce are some mandatory properties within
> the POJO/JSON. I have attempted a number of different ways including using
> bean validator (@NotNull) as well as Jackson annotations
> (@JsonProperty((value = "departmentCode", required=true). However a call
> to the API without one of the mandatory fields works without throwing any
> error.
> The one way I have got it to work is by putting a check in the
> getDepartmentCode method for a null value which then throws a custom
> exception that I have created. I'm not sure if this is the best way to do it.
> if (departmentCode!= null) {
> return departmentCode;
> } else {
> throw new CustomJSONException("Department code is a required field"); }
> My rest dsl looks like the following;
> rest("").bindingMode(RestBindingMode.json).consumes("application/json")
> .produces("application/json")
> .post("jobcompletionevent").type(Job.class).outType(String.class).enableCO
> RS(true)
> .description("Adds a job ").id("AddJob").responseMessage().code(400)
> .message("Invalid JSON
> Request").endResponseMessage().responseMessage().code(200)
> .message("Valid Request
> Received").endResponseMessage().to("direct:jobEventDistributor");
> Can anyone point me in the right direction of how I should aim to handle this
> use case? Should this be done in the initial binding or as an extra step
> afterwards. Any pointers are much appreciated.
> Regards,
> Richard
View raw message