Make type
in ProblemDetail
nullable
#35294
Closed
+5
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make ProblemDetail type field nullable to improve JSON serialization
Background
According to RFC 9457 Section 3.1.1 the "type" member is optional and when not present, its value is assumed to be "about:blank". The current Spring implementation explicitly sets this default value, which results in all problem responses containing the unhelpful
"type": "about:blank"
field even when no specific problem type is needed.Changes
This change makes the
type
field nullable inProblemDetail
:setType(@Nullable URI type)
to accept null valuesgetType()
to return@Nullable URI
Assert.notNull()
validation that prevented null typesCompatibility
This change is completely non-breaking. Existing users will not notice any difference in behavior:
type
field is still initialized toBLANK_TYPE
("about:blank") by default"type": "about:blank"
for existing usage patternsThe only difference is that developers can now optionally set the type to
null
if they want cleaner JSON output without the default "about:blank" value.Benefits
Example
For users who want cleaner output, they can now do:
This change provides more flexibility while maintaining complete backward compatibility.