|
12 | 12 | import org.reactivecommons.async.rabbit.RabbitMessage;
|
13 | 13 |
|
14 | 14 | import java.io.IOException;
|
15 |
| -import java.io.UnsupportedEncodingException; |
16 |
| -import java.nio.charset.Charset; |
17 | 15 | import java.nio.charset.StandardCharsets;
|
18 | 16 |
|
19 | 17 | public class JacksonMessageConverter implements MessageConverter {
|
20 |
| - private static final String ENCODING = Charset.defaultCharset().name(); |
21 | 18 | private static final String CONTENT_TYPE = "application/json";
|
22 | 19 |
|
23 | 20 | private final ObjectMapper objectMapper;
|
@@ -63,9 +60,7 @@ public <T> Command<T> readCommand(Message message, Class<T> bodyClass) {
|
63 | 60 | @Override
|
64 | 61 | public <T> T readValue(Message message, Class<T> valueClass) {
|
65 | 62 | try {
|
66 |
| - byte[] utf8Body = ensureEncoding(message.getBody(), message.getProperties().getContentEncoding(), |
67 |
| - StandardCharsets.UTF_8.name()); |
68 |
| - return objectMapper.readValue(utf8Body, valueClass); |
| 63 | + return objectMapper.readValue(message.getBody(), valueClass); |
69 | 64 | } catch (IOException e) {
|
70 | 65 | throw new MessageConversionException("Failed to convert Message content", e);
|
71 | 66 | }
|
@@ -97,25 +92,17 @@ public Message toMessage(Object object) {
|
97 | 92 | byte[] bytes;
|
98 | 93 | try {
|
99 | 94 | String jsonString = this.objectMapper.writeValueAsString(object);
|
100 |
| - bytes = jsonString.getBytes(ENCODING); |
| 95 | + bytes = jsonString.getBytes(StandardCharsets.UTF_8); |
101 | 96 | } catch (IOException e) {
|
102 | 97 | throw new MessageConversionException("Failed to convert Message content", e);
|
103 | 98 | }
|
104 | 99 | RabbitMessage.RabbitMessageProperties props = new RabbitMessage.RabbitMessageProperties();
|
105 | 100 | props.setContentType(CONTENT_TYPE);
|
106 |
| - props.setContentEncoding(ENCODING); |
| 101 | + props.setContentEncoding(StandardCharsets.UTF_8.name()); |
107 | 102 | props.setContentLength(bytes.length);
|
108 | 103 | return new RabbitMessage(bytes, props);
|
109 | 104 | }
|
110 | 105 |
|
111 |
| - private byte[] ensureEncoding(byte[] data, String fromEncoding, String toEncoding) |
112 |
| - throws UnsupportedEncodingException { |
113 |
| - if (fromEncoding.equalsIgnoreCase(toEncoding)) { |
114 |
| - return data; |
115 |
| - } |
116 |
| - return new String(data, fromEncoding).getBytes(toEncoding); |
117 |
| - } |
118 |
| - |
119 | 106 | @Data
|
120 | 107 | private static class AsyncQueryJson {
|
121 | 108 | private String resource;
|
|
0 commit comments