question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jackson ProblemModule is not registered properly when stacktrace is turned off

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
DirkvanWijkcommented, Mar 30, 2021

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!

0reactions
whiskeysierracommented, Mar 29, 2021

Although I’d expect our tests to fail then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

zalando/problem-spring-web - Stacktrace in response - GitHub
Stack traces are enabled by default, not disabled. ... but that you're in fact properly registering the ProblemModule in your ObjectMapper .
Read more >
zalando problem-spring-web generates unwanted stack trace
After some debugging, it seems that the ProblemModule is not registered in the ObjectMapper that is used to serialize the problem (its ...
Read more >
A Guide to the Problem Spring Web Library - Baeldung
Learn how to use the Problem Spring Web library to create messages with the errors' details using an application/problem+json response.
Read more >
Stack trace not included in re-thrown exception
When re-throwing an exception, make sure to include the stack trace. Otherwise pertinent debug information is lost. Detector ID.
Read more >
how to disable stack trace with BIRT 2.6.1 - Eclipse
I need to stop stack track information comming back to the browser if a report design file is not found or fails, its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found