differentiate between pass-through and byte[] for DaprObjectSerializer
- Lenguaje dominante
- Java
- Estrellas
- 300
- Forks
- 230
- Merge medio
- 5 d 1 h
- PR fusionados (30 d)
- 5
Descripción
## 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:
Guía de contribución
Línea de trabajo
Comienza con sdk/src/main/java/io/dapr/serializer/DaprObjectSerializer.java y DefaultObjectSerializer.java, utilizando las definiciones enlazadas como puntos de entrada. Verifica cómo la elección explícita de passThrough debe distinguir entre byte[] sin procesar y byte[] serializados normalmente, preservando al mismo tiempo el comportamiento predeterminado existente; se considera terminado cuando ambos serializers respetan esa elección.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- java
- Área
- backend-api-design
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100