-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow dynamic properties in ProblemDetail #28665
Comments
@rstoyanchev, getting unknown properties mapped to a single field can be tricky for Jackson. Even though this ticket is closed, I would strongly encourage adding tests for checking whether both de- and serialization works as expected. |
@vy, happy to re-open and make further updates. That said, from Jackson's perspective, isn't it just a straight-forward |
I think we have a misunderstanding about the use case here. Let me try to clarify it with an example. Let the server have a import org.springframework.http.ProblemDetail;
public class CustomProblemDetail extends ProblemDetail {
private final String host;
public CustomProblemDetail(ProblemDetail parent, String host) {
super(parent);
this.host = host;
}
public void setHost(String host) {
this.host = host;
}
public String getHost() {
return this.host;
}
} Due to a service failure, the server responds with a {
"type": "/problem/bad-request",
"title": "Bad Request",
"status": 400,
"detail": "miserable failure",
"instance": "/greeting",
"host": "awesome-x3csd3.bol.com"
} Note the extra Since the client doesn't know about the |
Thanks for clarifying. The goal is to avoid dependency on any serialization technology at the lowest level. Extra properties and serialization magic remain as a separate layer, through sub-classes and a global exception handler cloning the original exception to create the sub-class, as with your Originally I left I'm thinking that we should add a What do you think? |
I am happy to hear that we are on the same page. (And thanks so much for hearing me out! 🙏)
I think they certainly are! Ideally people shouldn't subclass
What about introducing a The reason I prefer a mix-in compared to a |
No worries, and thanks for tracking this and providing feedback. This is very much appreciated! Good suggestion for the Jackson mix-in. We'll go with that and register it automatically from |
There is a need for a generic map of properties in
ProblemDetail
for properties that are not known ahead of time, and cannot be exposed as setters from a subclass. Based on feedback on #27052 (comment) and #27052 (comment),The text was updated successfully, but these errors were encountered: