differentiate between pass-through and byte[] for DaprObjectSerializer
- Vorherrschende Sprache
- Java
- Sterne
- 300
- Forks
- 230
- Ø Merge
- 5 T. 1 Std.
- Gemergte PRs (30 T.)
- 5
Beschreibung
## 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:
Beitragsleitfaden
Rechercherichtung
Beginne mit sdk/src/main/java/io/dapr/serializer/DaprObjectSerializer.java und DefaultObjectSerializer.java und verwende die verknüpften Definitionen als Einstiegspunkte. Überprüfe, wie die explizite passThrough-Auswahl rohe byte[] von normal serialisierten byte[] unterscheiden soll, während das bestehende Standardverhalten erhalten bleibt; als erledigt gilt die Aufgabe, wenn beide Serializer diese Auswahl berücksichtigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- backend-api-design
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100