rest
rest copied to clipboard
New method MediaType.getCharsetParameter() returns charset instance or null
Proposal
I like to propose the addition of the new method MediaType.getCharsetParameter() which either returns a Charset instance, null, or throws UnsupportedCharsetException.
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
public static Charset getCharset(MediaType m) {
String name = (m == null) ? null : m.getParameters().get(MediaType.CHARSET_PARAMETER);
return (name == null) ? StandardCharsets.UTF_8 : Charset.forName(name);
}
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? 😃