Map from charset name rather than Charset
With this commit it is no longer assumed that all charset names in the JsonEncoding can be resolved by Charset.forName. Instead, we store the charset name itself, rather than the Charset object.
This commit is contained in:
parent
0a208a4941
commit
405fdd3a57
|
|
@ -69,7 +69,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||
|
||||
private static final Map<MediaType, byte[]> STREAM_SEPARATORS;
|
||||
|
||||
private static final Map<Charset, JsonEncoding> ENCODINGS;
|
||||
private static final Map<String, JsonEncoding> ENCODINGS;
|
||||
|
||||
static {
|
||||
STREAM_SEPARATORS = new HashMap<>(4);
|
||||
|
|
@ -78,8 +78,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||
|
||||
ENCODINGS = new HashMap<>(JsonEncoding.values().length);
|
||||
for (JsonEncoding encoding : JsonEncoding.values()) {
|
||||
Charset charset = Charset.forName(encoding.getJavaName());
|
||||
ENCODINGS.put(charset, encoding);
|
||||
ENCODINGS.put(encoding.getJavaName(), encoding);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +115,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||
}
|
||||
if (mimeType != null && mimeType.getCharset() != null) {
|
||||
Charset charset = mimeType.getCharset();
|
||||
if (!ENCODINGS.containsKey(charset)) {
|
||||
if (!ENCODINGS.containsKey(charset.name())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -287,7 +286,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||
protected JsonEncoding getJsonEncoding(@Nullable MimeType mimeType) {
|
||||
if (mimeType != null && mimeType.getCharset() != null) {
|
||||
Charset charset = mimeType.getCharset();
|
||||
JsonEncoding result = ENCODINGS.get(charset);
|
||||
JsonEncoding result = ENCODINGS.get(charset.name());
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ import org.springframework.util.TypeUtils;
|
|||
*/
|
||||
public abstract class AbstractJackson2HttpMessageConverter extends AbstractGenericHttpMessageConverter<Object> {
|
||||
|
||||
private static final Map<Charset, JsonEncoding> ENCODINGS = jsonEncodings();
|
||||
private static final Map<String, JsonEncoding> ENCODINGS = jsonEncodings();
|
||||
|
||||
/**
|
||||
* The default charset used by the converter.
|
||||
|
|
@ -184,7 +184,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
|||
}
|
||||
if (mediaType != null && mediaType.getCharset() != null) {
|
||||
Charset charset = mediaType.getCharset();
|
||||
if (!ENCODINGS.containsKey(charset)) {
|
||||
if (!ENCODINGS.containsKey(charset.name())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -247,7 +247,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
|||
MediaType contentType = inputMessage.getHeaders().getContentType();
|
||||
Charset charset = getCharset(contentType);
|
||||
|
||||
boolean isUnicode = ENCODINGS.containsKey(charset);
|
||||
boolean isUnicode = ENCODINGS.containsKey(charset.name());
|
||||
try {
|
||||
if (inputMessage instanceof MappingJacksonInputMessage) {
|
||||
Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
|
||||
|
|
@ -374,7 +374,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
|||
protected JsonEncoding getJsonEncoding(@Nullable MediaType contentType) {
|
||||
if (contentType != null && contentType.getCharset() != null) {
|
||||
Charset charset = contentType.getCharset();
|
||||
JsonEncoding encoding = ENCODINGS.get(charset);
|
||||
JsonEncoding encoding = ENCODINGS.get(charset.name());
|
||||
if (encoding != null) {
|
||||
return encoding;
|
||||
}
|
||||
|
|
@ -399,9 +399,9 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
|||
return super.getContentLength(object, contentType);
|
||||
}
|
||||
|
||||
private static Map<Charset, JsonEncoding> jsonEncodings() {
|
||||
private static Map<String, JsonEncoding> jsonEncodings() {
|
||||
return EnumSet.allOf(JsonEncoding.class).stream()
|
||||
.collect(Collectors.toMap(encoding -> Charset.forName(encoding.getJavaName()), Function.identity()));
|
||||
.collect(Collectors.toMap(JsonEncoding::getJavaName, Function.identity()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue