Jackson ProblemModule is not registered properly when stacktrace is turned off
See original GitHub issueDescription
Hi, we have a java EE application with a few REST APIs. We a few exceptionMappers that basically return a Problem object in the response body (very similar to the traits that are part of the spring library https://github.com/zalando/problem-spring-web/blob/main/problem-spring-web/src/main/java/org/zalando/problem/spring/web/advice/AdviceTrait.java )
When I register the ProblemModule in my Jackson ObjectMapper in these two manners:
.registerModule(ProblemModule())
or .registerModule(ProblemModule().withStackTraces(false))
I get stacktraces in the form of an array:
{
"status": 404,
"stackTrace": [
{
"declaringClass": "org.zalando.problem.ProblemBuilder",
"methodName": "build",
"fileName": "ProblemBuilder.java",
"lineNumber": 83,
"className": "org.zalando.problem.ProblemBuilder",
"nativeMethod": false
},
{
"declaringClass": "....handlers.NotFoundExceptionHandler",
"methodName": "toResponse",
"fileName": "NotFoundExceptionHandler.kt",
"lineNumber": 24,
"className": "...handlers.NotFoundExceptionHandler",
"nativeMethod": false
},
This implies that the ProblemModule is not registered correctly, and the default jackson serialization is used (is what I can deduct from other previous bug reports).
However, when I register the module like this:
.registerModule(ProblemModule().withStackTraces(true))
I get the stacktrace in a different format (probably generated by the ProblemModule):
"status": 404, "stacktrace": [ "org.zalando.problem.ProblemBuilder.build(ProblemBuilder.java:83)", "...handlers.NotFoundExceptionHandler.toResponse(NotFoundExceptionHandler.kt:24)", ...handlers.NotFoundExceptionHandler.toResponse(NotFoundExceptionHandler.kt:17)",
As a workaround, when I manually empty the stacktrace field of the created Problem object, I get no stacktrace in the response.
Expected Behavior
I’m expecting that the stackTrace field in the response is entirely empty when the stacktrace setting is turned off.
Actual Behavior
When the stacktrace setting is on false, the ProblemModule seems to be no longer registered.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top GitHub Comments
This is a bit embarrassing, but I found the issue… In our ObjectMapper we had this line:
defaultObjectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY)
(Not fully sure anymore why we added it, it was when experimenting with an Interceptor to turn our original response into a Problem response). After deleting this line, the stacktrace is gone.Thanks for the help and quick response anyway!
Although I’d expect our tests to fail then.