#1313 - Override Problem.withStatus in ExtendedProblem to preserve payload.

When you use the withStatus() method on an ExtendedProblem, it hands back a Problem, which drops the payload. This commit adds the same sort of override already provided for the other attributes in ExtendedProblem.
This commit is contained in:
Greg L. Turnquist
2020-06-26 11:02:54 -05:00
parent f3198b7d79
commit 27fe7de1c9
3 changed files with 12 additions and 1 deletions

View File

@@ -195,6 +195,15 @@ public class Problem {
return new ExtendedProblem<>(getType(), title, getStatus(), getDetail(), getInstance(), extendedProperties);
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.mediatype.problem.Problem#withStatus(org.springframework.http.HttpStatus)
*/
@Override
public ExtendedProblem<T> withStatus(@Nullable HttpStatus status) {
return new ExtendedProblem<>(getType(), getTitle(), status, getDetail(), getInstance(), extendedProperties);
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.mediatype.problem.Problem#withDetail(java.lang.String)

View File

@@ -219,6 +219,7 @@ class JacksonSerializationTest {
ExtendedProblem<AccountProblemDetails> problem = Problem.create(details)
.withType(URI.create("https://example.com/probs/out-of-credit")) //
.withTitle("You do not have enough credit.") //
.withStatus(HttpStatus.BAD_REQUEST) //
.withDetail("Your current balance is 30, but that costs 50.") //
.withInstance(URI.create("/account/12345/msgs/abc"));

View File

@@ -4,5 +4,6 @@
"detail" : "Your current balance is 30, but that costs 50.",
"instance" : "/account/12345/msgs/abc",
"balance" : 30,
"accounts" : [ "/account/12345", "/account/67890" ]
"accounts" : [ "/account/12345", "/account/67890" ],
"status" : 400
}