problem-spring-web: Custom data for all problem exceptions

Hi!

I want to add different values to all exceptions. For example zipkin traceId.

I have added:

@Configuration
class SpringDataRestConfiguration extends RepositoryRestConfigurerAdapter {

  @Override
  public void configureJacksonObjectMapper(ObjectMapper objectMapper) {
    objectMapper
        .registerModule(new ProblemModule())
        .registerModule(new ConstraintViolationProblemModule());
  }
}

but when I try to override methods in:

@ControllerAdvice
class GlobalExceptionHandler implements ProblemHandling {
}

I end up with getting the full problem serialized cause, stackTrace, etc.

I must have misunderstood anything about the customization. But do you have any good way to add custom data and how to do the customization?

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (3 by maintainers)

Most upvoted comments

@dominikmontada Have you implemented this/are you willing to share a pull request? I don’t know what the team’s thoughts are on this are but I agree that the current approach of creating a serialisation module is convoluted.

Maybe adding a toProblemBuilder() method in Problem would help (forcing implementations to implement it) ?

Exactly. No, there is no good workaround to me knowledge at least. Custom JSON post-processor using Jackson + Spring, maybe. But it won’t be nice either.

I’m closing this, as I believe that this should rather be achieved using Jackson. @Torsph @cbornet Feel free to re-open/object.