Affects: org.springframework:spring-messaging:5.3.6
We are using org.springframework:spring-messaging:5.3.6 with com.google.protobuf:protobuf-java:3.13.0 and com.google.protobuf:protobuf-java-util:3.13.0 to send and receive protobuf messages as application/json.
static class ProtobufJavaUtilSupport implements ProtobufFormatSupport {
...
@Override
public void merge(org.springframework.messaging.Message<?> message, Charset charset,
MimeType contentType, ExtensionRegistry extensionRegistry, Message.Builder builder)
throws IOException, MessageConversionException {
if (contentType.isCompatibleWith(APPLICATION_JSON)) {
this.parser.merge(message.getPayload().toString(), builder);
}
else {
throw new MessageConversionException(
"protobuf-java-util does not support parsing " + contentType);
}
}
...
}
message.getPayload() returns a byte array (GenericMessage [payload=byte[230], headers={...}]). Calling toString on a byte array produces a string similar to "[B@27fe3806".
Attempt to parse resulting string as JSON produces the following error:
com.google.protobuf.InvalidProtocolBufferException: java.io.EOFException: End of input at line 1 column 12 path $[1]
at com.google.protobuf.util.JsonFormat$ParserImpl.merge (JsonFormat.java:1347)
at com.google.protobuf.util.JsonFormat$Parser.merge (JsonFormat.java:477)
at org.springframework.messaging.converter.ProtobufMessageConverter$ProtobufJavaUtilSupport.merge (ProtobufMessageConverter.java:265)
at org.springframework.messaging.converter.ProtobufMessageConverter.convertFromInternal (ProtobufMessageConverter.java:150)
I assume that byte arrays need special handling so that we use String constructor instead of toString() call in order to get actual JSON content (i.e. something akin to new String(message.getPayload(), StandardCharsets.UTF_8)).
Affects: org.springframework:spring-messaging:5.3.6
We are using org.springframework:spring-messaging:5.3.6 with com.google.protobuf:protobuf-java:3.13.0 and com.google.protobuf:protobuf-java-util:3.13.0 to send and receive protobuf messages as application/json.
message.getPayload()returns a byte array (GenericMessage [payload=byte[230], headers={...}]). CallingtoStringon a byte array produces a string similar to "[B@27fe3806".Attempt to parse resulting string as JSON produces the following error:
I assume that byte arrays need special handling so that we use String constructor instead of
toString()call in order to get actual JSON content (i.e. something akin tonew String(message.getPayload(), StandardCharsets.UTF_8)).