dapr / dapr/java-sdk

differentiate between pass-through and byte[] for DaprObjectSerializer

Aperta
#500 17 commenti 0 reazioni 0 assegnatari Vedi su GitHub
kind/bug question
Lingua principale
Java
Stelle
300
Fork
230
Merge medio
5g 1h
PR unite (30g)
5

Descrizione

## Expected 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](https://github.com/dapr/java-sdk/blob/9296a8332336333ead172f460fb3b2209c446acb/sdk/src/main/java/io/dapr/serializer/DaprObjectSerializer.java#L15) does not differentiate between pass-through byte[] and normal byte[] values. The [DefaultObjectSerializer](https://github.com/dapr/java-sdk/blob/9296a8332336333ead172f460fb3b2209c446acb/sdk/src/main/java/io/dapr/serializer/DefaultObjectSerializer.java#L16) 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](https://github.com/dapr/java-sdk/blob/9296a8332336333ead172f460fb3b2209c446acb/sdk/src/main/java/io/dapr/serializer/DaprObjectSerializer.java#L15) to follows:
```java
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 deserialize(byte[] data, TypeRef type) throws IOException {
return deserialize(data, type, true);
}

T deserialize(byte[] data, TypeRef type, boolean passThrough) throws IOException;

String getContentType();
}
```
and [DefaultObjectSerializer](https://github.com/dapr/java-sdk/blob/9296a8332336333ead172f460fb3b2209c446acb/sdk/src/main/java/io/dapr/serializer/DefaultObjectSerializer.java#L16) should be changed to honor explicit passThrough param.

## Steps to Reproduce the Problem

## Release Note

RELEASE NOTE:

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.