I am trying to implement an endpoint which takes a List<SomeClass>
via @RequestBody
and supports partial processing / fault tolerancy.
As in, even if some elements are wrong (may even be different type, but still valid JSON), discard them and continue with the next one instead of throwing an exception and failing fast.
I am already calling the validator programmatically on each element instead of utilizing @Valid
, but whenever I receive something with different schema or type, I get a com.fasterxml.jackson.databind.exc.MismatchedInputException
.
How can I change this behavior to not fail but ignore and process the next element instead?
I am using Spring Boot 2.2.3.RELEASE
.
I tried using @JsonIgnoreProperties(ignoreUnknown = true)
, but when I receive non-object types, the exception is still thrown.
Example JSON I'd like to process:
[
null,
[],
{},
-1,
false,
"Test",
{ "someKey": "someValue" }
]
Where only { "someKey": "someValue" }
is a valid SomeClass
definition.