-
Notifications
You must be signed in to change notification settings - Fork 628
JsonMapper.isJsonStringRepresentsCollection may incorrectly return true for Protobuf-encoded messages #1094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What contentType are you passing as message header? |
We use the ProtobufMessageConverter, which sets the content type to However, as mentioned above, this is not limited to protobuf-encoded messages. From code inspection it's pretty clear that any serialization that is not JSON can cause that problem. |
Conversion of protobuf messages fails if the encoded message looks like a JSON string. Added a test that reproduces the issue.
This is becoming a real problem for us. I have added a test that reproduces the issue. |
Conversion of protobuf messages fails if the encoded message looks like a JSON string. Added a test that reproduces the issue.
Conversion of protobuf messages fails if the encoded message looks like a JSON string. Added a test that reproduces the issue.
Sorry for neglecting it. Will look at it shortly |
While I added
|
I need to ask why we have to configure a JSON mapper if we don't use JSON for our messages at all. The content type says the message is not JSON, so IMHO With this "auto-sensing" of the content type we can probably still construct a failing scenario, i.e. a serialization that sometimes produces a valid JSON string, but isn't meant to be interpreted as JSON. What am I missing? |
No, you are not missing anything, but got me thinking if I can also check for content-type and if it is not application/json why bother . . . that I agree, so let me try something. I'll re-open the issue |
Thanks for reopening this - we already found that the whole thing is skipped if the content type is plain text (https://github.com/spring-cloud/spring-cloud-function/blob/main/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistry.java#L857). Maybe the simplest fix would be to reverse this logic and call the JsonMapper only if the content type is undefined oder "application/json". |
The problem is that not everything comes as Message, hence no way of communicating content-type. |
Anyway, I have reverted the commit that would force you to provide the mentioned settings as I agree you don't need to do that when no using JSON. |
Using
Spring Boot 2.7.11
Spring Cloud Dependencies 2021.0.8
Describe the bug
Note: We ran into this issue with Protobuf encoded messages, but it should be reproducible with any binary serialization.
A Protobuf message with length encoded fields like
is encoded into a tag, followed by the length of the encoded value (in bytes), followed by the payload. The tag is fieldNumber * 8 + 2 (see Protobuf wire types) = 10 in this example.
isJsonStringRepresentsCollection()
strips the tag from the input if it has the same numeric representation as some whitespace character (newline in this case).If the payload happens to be 34, 91, or 123 bytes long and end with 34 resp. 93 resp. 125 (decimal representation),
isJsonStringRepresentsCollection()
identifies the remaining input as JSON andfluxifyInputIfNecessary()
callsfromJson()
, which inevitably fails at some point with something likeThe real culprit here seems to be
fluxifyInputIfNecessary()
, which ignores the content type header of a message entirely (almost, text/plain is handled). IMOfromJson()
should only be called if the content type is undefined or application/json.The text was updated successfully, but these errors were encountered: