ServerJacksonMessageBodyReader and JacksonBasicMessageBodyReader "should" catch JsonProcessingException
See original GitHub issueDescribe the bug
When de-serializing JSON in a request, we want to catch client input errors due to malformed data. Unfortunately, we have run into situations where the exception Jackson is throwing is one of several JsonProcessingExceptions, i.e., a JsonMappingException, JsonParseException or DatabindException. As a result, the intended BAD_REQUEST is met with a SERVER_ERROR.
Using ExceptionMappers can work, if we are diligent in catching JsonProcessingException’s in any location we use an ObjectMapper. If we are not diligent, then an ExceptionMapper will lead to a client error when it is actually a server error.
Corresponding locations: JacksonBasicMessageBodyReader
ServerJacksonMessageBodyReader
Updating these locations to catch JsonProcessingException should resolve the issues we are seeing.
Expected behavior
BAD_REQUEST is thrown when input is malformed.
Actual behavior
SERVER_ERROR is thrown.
How to Reproduce?
This is a simplified version of what we are doing, only the details causing the issue are included.
public class Data {
private String type;
@JsonCreator
public Data(
@JsonProperty("type") String type
...
) {
this.type = Objects.requireNonNull(type);
}
}
Deserialize with the following line of code (throws a ValueInstantiationException):
mapper.readValue("{}", Data.class)
When via a controller, i.e., we should get 400 if the request body is “{}”.
public Controller {
@POST
@Path("/")
public void receive(Data data) {
}
}
Output of uname -a
or ver
Darwin Kernel Version 21.6.0: Thu Sep 29 20:12:57 PDT 2022; root:xnu-8020.240.7~1/RELEASE_X86_64
Output of java -version
17.0.3 (Eclipse Adoptium 17.0.3+7)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.8.3-Final
Build tool (ie. output of mvnw --version
or gradlew --version
)
------------------------------------------------------------ Gradle 7.3 ------------------------------------------------------------ Build time: 2021-11-09 20:40:36 UTC Revision: 96754b8c44399658178a768ac764d727c2addb37 Kotlin: 1.5.31 Groovy: 3.0.9 Ant: Apache Ant™ version 1.10.11 compiled on July 10 2021 JVM: 17.0.3 (Eclipse Adoptium 17.0.3+7) OS: Mac OS X 12.6.1 x86_64
Additional information
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:13 (12 by maintainers)
@geoand, my replacement PR has been linked above.
Thanks again for all your help.
Sure