Skip to content

Commit 7f9e541

Browse files
committed
Merge branch '6.1.x'
2 parents 7183a19 + 6dd5c85 commit 7f9e541

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -265,7 +265,12 @@ public void merge(org.springframework.messaging.Message<?> message, Charset char
265265
throws IOException, MessageConversionException {
266266

267267
if (contentType.isCompatibleWith(APPLICATION_JSON)) {
268-
this.parser.merge(message.getPayload().toString(), builder);
268+
if (message.getPayload() instanceof byte[] bytes) {
269+
this.parser.merge(new String(bytes, charset), builder);
270+
}
271+
else {
272+
this.parser.merge(message.getPayload().toString(), builder);
273+
}
269274
}
270275
else {
271276
throw new MessageConversionException(

spring-messaging/src/test/java/org/springframework/messaging/converter/ProtobufMessageConverterTests.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.messaging.converter;
1818

19+
import java.nio.charset.StandardCharsets;
1920
import java.util.Map;
2021

2122
import org.junit.jupiter.api.Test;
@@ -49,14 +50,14 @@ class ProtobufMessageConverterTests {
4950

5051
private Message<byte[]> messageWithoutContentType = MessageBuilder.withPayload(this.testMsg.toByteArray()).build();
5152

52-
private final Message<String> messageJson = MessageBuilder.withPayload("""
53+
private final Message<byte[]> messageJson = MessageBuilder.withPayload("""
5354
{
5455
"foo": "Foo",
5556
"blah": {
5657
"blah": 123
5758
}
5859
}
59-
""")
60+
""".getBytes(StandardCharsets.UTF_8))
6061
.setHeader(CONTENT_TYPE, APPLICATION_JSON)
6162
.build();
6263

@@ -113,10 +114,10 @@ void jsonWithGoogleProtobuf() throws Exception {
113114
Message<?> message = converter.toMessage(testMsg, new MessageHeaders(Map.of(CONTENT_TYPE, APPLICATION_JSON)));
114115
assertThat(message).isNotNull();
115116
assertThat(message.getHeaders().get(CONTENT_TYPE)).isEqualTo(APPLICATION_JSON);
116-
JSONAssert.assertEquals(messageJson.getPayload(), message.getPayload().toString(), true);
117+
JSONAssert.assertEquals(new String(messageJson.getPayload()), message.getPayload().toString(), true);
117118

118119
//convertFrom
119-
assertThat(converter.fromMessage(message, Msg.class)).isEqualTo(testMsg);
120+
assertThat(converter.fromMessage(messageJson, Msg.class)).isEqualTo(testMsg);
120121
}
121122

122123
}

0 commit comments

Comments
 (0)