Skip to content

Commit 30a573d

Browse files
garyrussellartembilan
authored andcommitted
GH-1252: Jackson Converter Polishing
Resolves #1253 Misleading field name `standardCharset`. It was meant to convey that Jackson's default charset (UTF-8) is being used and so we can convert directly to `byte[]`. Otherwise we convert to `String` and then to `byte[]` using the configured charset. Also, it was not set to `true` by default.
1 parent 4f76b2b commit 30a573d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

spring-amqp/src/main/java/org/springframework/amqp/support/converter/AbstractJackson2MessageConverter.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public abstract class AbstractJackson2MessageConverter extends AbstractMessageCo
8484

8585
private ProjectingMessageConverter projectingConverter;
8686

87-
private boolean standardCharset;
87+
private boolean charsetIsUtf8 = true;
8888

8989
private boolean assumeSupportedContentType = true;
9090

@@ -125,9 +125,7 @@ public void setClassMapper(ClassMapper classMapper) {
125125
public void setDefaultCharset(@Nullable String defaultCharset) {
126126
this.defaultCharset = (defaultCharset != null) ? Charset.forName(defaultCharset)
127127
: DEFAULT_CHARSET;
128-
if (this.defaultCharset.equals(StandardCharsets.UTF_8)) {
129-
this.standardCharset = true;
130-
}
128+
this.charsetIsUtf8 = this.defaultCharset.equals(StandardCharsets.UTF_8);
131129
}
132130

133131
public String getDefaultCharset() {
@@ -371,7 +369,7 @@ protected Message createMessage(Object objectToConvert, MessageProperties messag
371369

372370
byte[] bytes;
373371
try {
374-
if (this.standardCharset) {
372+
if (this.charsetIsUtf8) {
375373
bytes = this.objectMapper.writeValueAsBytes(objectToConvert);
376374
}
377375
else {

0 commit comments

Comments
 (0)