Add a 'toBuilder' method, for enhancing defaulted Problems

Open
#507 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java

Research direction

Start by reading ProblemBuilder, Problem, and ConstraintViolationProblem, then inspect how the Jackson mixin preserves the violations field. Trace the ResponseBodyAdviceProblem use case described in the issue. Done should provide a way to add parameters while retaining the original problem type and its type-specific serialized data.

Written by the indexing model from the issue text.

Description

Feature

Detailed Description

We use the default error-handling provided by org.zalando.problem.spring.web.advice.ProblemHandling extensively in our application.

We also wish to add a trace ID parameter to all Problem responses. To do this, I thought to add a ResponseBodyAdvice<Problem> which copies the intercepted problem to a new ProblemBuilder, adds the trace ID, and returns the rebuilt problem to be the 'actual' response body.

However, in doing so, we end up breaking ConstraintViolationProblem, which no longer includes the violations field in the response JSON, because the Jackson mixin for violations is no longer used.

But ConstraintViolationProblem does not itself expose a way to set additional parameters.

I can get around this by subclassing ConstraintViolationProblem and exposing getParameters. But in future, there may be some other problem type whose type-specific data is 'lost'.

It would be great to have some way to clone a problem and retain its original type, while also providing additional parameters. Perhaps there's a way to do this and I just haven't found it yet?

Context

Adding extra information to framework-built Problem responses.

Your Environment

org.zalando:problem:0.27.0
org.zalando:problem-spring-web:0.27.0

Dominant language
Java
Stars
951
Forks
99
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from zalando/problem

All issues in zalando/problem

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.