quarkiverse / quarkus-dapr

The Distributed Application Runtime (Dapr) provides APIs that simplify microservice connectivity
https://dapr.io/
Apache License 2.0
31 stars 16 forks source link

Error when the state store there is no data #146

Closed mcruzdev closed 9 months ago

mcruzdev commented 9 months ago

When we want to get a state without data:

        // There is no key called "values"
        State<Values> state = dapr.getState(stateStoreName, VALUES_KEY_NAME, Values.class);

And there is no key into the store, we got the following message:

Error id 34e2d8af-e268-455c-bf9c-c988faa4583f-1, io.dapr.exceptions.DaprException: UNKNOWN: No content to map due to end-of-input",
    "stack": "io.dapr.exceptions.DaprException: UNKNOWN: No content to map due to end-of-input\n at [Source: (byte[])\"\"; line: 1, column: 0]\n\tat 

After some researching I added a validation in JacksonDaprObjectSerializer class:


    @Override
    public <T> T deserialize(byte[] data, TypeRef<T> type) throws IOException {
        // validation here
        if (data.length == 0) {
             return null;
        }

        return this.objectMapper.readValue(data, this.objectMapper.constructType(type.getType()));
    }

I added this configuration o ObjectMapper:

        objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);

But without sucesss.

I do not know if makes sense send a pull request adding this validation (data.length == 0) return null.

What do you think @naah69 and @zhfeng ?

I am using a in-memory state with this application:

https://github.com/mcruzdev/dapr-devservices/blob/f227955e2887224cd72adf574973cb891354017b/writer/src/main/java/dev/matheuscruz/MessageResource.java#L49

mcruzdev commented 9 months ago

Hi @zhfeng how are you? I created the pull request as mentioned in the previous issue, could you review it? TY!

mcruzdev commented 9 months ago

Hi @naah69 and @skyao, can you take a look on this issue? I opened a pull request to fix this error #156