Automatically unwrap pub/sub CloudEvent
Background
In the Dapr SDK for .NET, one can configure the SDK to automatically unwrap CloudEvents that an application receives over pub/sub using app.UseCloudEvents().
The Dapr SDK for Java, however, only lets you receive a CloudEvent. It provides access to the underlying message using getData, but that method returns an Object. According to the specs, this can be a JSON object or string. This means in practice it can be anything - for complex types, it will most likely be a java.util.Map.
Proposal
It would be cool if the SDK for Java would allow to unwrap a CloudEvent in the same way as the SDK for .NET does.
Alternatives
As an alternative, if the CloudEvent class would be a generic class with one type parameter that describes the type of the data, field, it would at least make it a lot easier to unwrap the CloudEvent by declaring it of the right type and then calling getData() on it. I did a quick & dirty PoC by copying the CloudEvent class into my application and making it generic, and Jackson (the default serializer) seems to handle perfectly well.
Automatically unwrap pub/sub CloudEvent
Background
In the Dapr SDK for .NET, one can configure the SDK to automatically unwrap CloudEvents that an application receives over pub/sub using
app.UseCloudEvents().The Dapr SDK for Java, however, only lets you receive a
CloudEvent. It provides access to the underlying message usinggetData, but that method returns anObject. According to the specs, this can be a JSON object or string. This means in practice it can be anything - for complex types, it will most likely be ajava.util.Map.Proposal
It would be cool if the SDK for Java would allow to unwrap a
CloudEventin the same way as the SDK for .NET does.Alternatives
As an alternative, if the
CloudEventclass would be a generic class with one type parameter that describes the type of thedata, field, it would at least make it a lot easier to unwrap theCloudEventby declaring it of the right type and then callinggetData()on it. I did a quick & dirty PoC by copying theCloudEventclass into my application and making it generic, and Jackson (the default serializer) seems to handle perfectly well.