New method MediaType.getCharsetParameter() returns charset instance or null #1305
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.
Proposal
I like to propose the addition of the new method
MediaType.getCharsetParameter()
which either returns aCharset
instance,null
, or throwsUnsupportedCharsetException
.Justification
Rather often I came across code like the following lines (quoted from Jersey) in applications, filters and compliant implementations:
https://github.com/eclipse-ee4j/jersey/blob/b128e9c9e649e96488a9c1d367e4cbae89a9d1d4/core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderWriter.java#L127-L130
I do not see any benefit in repeating the obvious again and again, so why not giving away this standard solution for free as part of JAX-RS itself? 😃