differentiate between pass-through and byte[] for DaprObjectSerializer
See original GitHub issueExpected Behavior
byte[] can means 2 things.
- pass-through: do not serialize/deserialize the values. Sent/return the raw data. Other parts of the system will deal with raw data.
- normal byte[] values: serialize/deserialize them normally.
Actual Behavior
Current DaprObjectSerializer does not differentiate between pass-through byte[] and normal byte[] values. The DefaultObjectSerializer treats byte[] as always pass-through.
There are cases when serializing/deserializing byte[] as normal values is desired. For example, for json, it’s desired to serialize byte[] as base64-encoded String because there’s no other way to represent byte[] as legal JSON values.
I suggest to change the DaprObjectSerializer to follows:
public interface DaprObjectSerializer {
default byte[] serialize(Object o) throws IOException {
// passThrough by default true, to make this not a breaking change.
return serialize(o, true);
}
byte[] serialize(Object o, boolean passThrough) throws IOException;
default <T> T deserialize(byte[] data, TypeRef<T> type) throws IOException {
return deserialize(data, type, true);
}
<T> T deserialize(byte[] data, TypeRef<T> type, boolean passThrough) throws IOException;
String getContentType();
}
and DefaultObjectSerializer should be changed to honor explicit passThrough param.
Steps to Reproduce the Problem
Release Note
RELEASE NOTE:
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (17 by maintainers)
Top Results From Across the Web
java-sdk/JavaSerializer.java at master · dapr/java-sdk - GitHub
* Class used to test different serializer implementations. */. public class JavaSerializer implements DaprObjectSerializer {.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes. It’s the workaround we are currently using. But it’s not ideal.
https://github.com/dapr/dapr/issues/2905#issuecomment-796537346:
The users are forced to work around this by treating raw byte[] as "skipping serialization", which brings another issue. Another workaround (the one we are currently using) is creating multiple instances of Dapr client with different DaprObjectSerializer in order to work with different components.
To support serialization negotiation (https://github.com/dapr/dapr/issues/2905), I suggest the DaprObjectSerializer interface to be changed to:
getContentType()
method is removed. Content type (a.k.a. mimeType) should be a property (data-content-type
) for the input byte[] and output byte[], not the serializer.canSerialize()
andcanDeserialize()
are added to support serialization negotiation based ondata-content-type
.