I'm working on a system which uses Apache Camel and Spring-boot and I want my routes to return an error if an unknown parameter is sent in the request object.
I know how to do that with Jackson directly (configuring the object-mapper bean) but, in my case, the route is configured without the possibility to pass an opportune custom object mapper.
In fact, in my route I have:
from(...)
.unmarshal().json(JsonLibrary.Jackson, MyInputDtoClass.class)
.process(FirstProcessor.BEAN)
.process(SecondProcessor.BEAN)
.to(OtherRoute.ROUTE)
If I add the Jackson annotation on my MyInputDtoClass:
@JsonIgnoreProperties(ignoreUnknown = false)
public class MyInputDtoClass {
...
}
it still let the request to be unmarshalled even if I add unknown parameters in the Body of the Request. How to block sending unknown properties and return an error?
You can build a JacksonDataFormat for unmarshalling in your route:
Something like this