#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:
@@ -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)
|
||||
|
||||
@@ -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"));
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user