question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing fields in CloudEvent deserialisation

See original GitHub issue

Raising this on behalf of a colleague who is on vacation


I have started using DAPR pub/sub and am creating a Subscription in a Springboot application, so I am using the JAVA sdk.

The subscriber receives the messages correctly, but I noticed that the CloudEvent class, used to deserialize the incoming event, is missing these fields tracid,traceparent,tracestate,topic,pubsubname.

I’m using these libraries

implementation 'io.dapr:dapr-sdk:1.5.0'
implementation 'io.dapr:dapr-sdk-actors:1.5.0'
implementation 'io.dapr:dapr-sdk-springboot:1.5.0'

I know that the last version is 1.6.0, but from the javadoc I saw that the CloudEvent class of that version miss the fields too.

cc @fvitolo

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
artursouzacommented, Aug 13, 2022

I have a similar issue. When creating a message in an app and then accessing it in another app I can’t deserialize the CloudEvent as excepted.

Roughly illustrating it:

App A creating the message:

val data = DaprPayload(input, singletonMap("templateId", templateId)). // Custom data type with added metadata

DaprClientBuilder().build().use { client ->
    client.publishEvent(
        daprConfig.pubsub.name,
        daprConfig.pubsub.topics.openehrInput,
        data,
        singletonMap(io.dapr.client.domain.Metadata.TTL_IN_SECONDS, "\${dapr.pubsub.ttl}")
    ).toFuture().get()
}

App B accessing it fails:

jsonMapper().readValue(body, CloudEvent::class.java)

It throws and error like Method threw 'com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException' exception. with this additional message Unrecognized field "pubsubname" (class io.dapr.client.domain.CloudEvent), not marked as ignorable.

The CloudEvent looks like this (on the pubsub component and how it gets into App B):

{
    "data": {
        "metadata": {
            "templateId": "..."
        },
        "payload": "..."
    },
    "datacontenttype": "application/json",
    "id": "9694d729-1373-4f21-9bd2-1f05681e04f9",
    "pubsubname": "pubsub",
    "source": "client",
    "specversion": "1.0",
    "topic": "openehr-input",
    "traceid": "00-668be055cfb8f2954b67c90f5fab0013-f85bc3e91ca83947-01",
    "traceparent": "00-668be055cfb8f2954b67c90f5fab0013-f85bc3e91ca83947-01",
    "tracestate": "",
    "type": "com.dapr.event.sent"
}

The mapper is not configured to ignore unknown attributes: mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)

Now, the fix here is to serialize the “unknown” attributes into a dictionary since it is not possible to hardcode every possible attribute in cloud event since the spec allows it to be extensible.

1reaction
yaron2commented, Aug 12, 2022

Based on https://github.com/dapr/components-contrib/blob/master/pubsub/envelope.go, the fields that can be in CloudEvent are not completely there in Java SDK model.

@artursouza @yaron2 Dapr has additional fields on top of the CloudEvents spect v1.0, for that I think publishing a proto file will be good. WDYT? Since this will be a moving target as and when new fields are included that are optional, mandating a proto definition would potentially help in having the model auto generated.

Makes sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deserialization fails when subject is null · Issue #430 - GitHub
We now have a problem, where a service uses cloudevents-json-jackson and gets a valid CloudEvent, but which does have the field subject set ......
Read more >
Batch Consumer not working with Kafka for CloudEvents ...
If I use any custom class with custom serializer/deserializer it is working fine but with cloudevents the messages are not coming.
Read more >
cloudevents.exceptions.MissingRequiredFields Example
Learn how to use python api cloudevents.exceptions. ... MissingRequiredFields): # CloudEvent constructor throws TypeError if missing required field # and ...
Read more >
Use CloudEvents v1.0 schema with Event Grid - Microsoft Learn
This schema allows for uniform tooling, standard ways of routing and handling events, and universal ways of deserializing the outer event schema ...
Read more >
Persisting Cloud Events to Cosmos DB in Azure
CloudEvents.CloudEvent'. Path: $ | LineNumber: 0 | BytePositionInLine: 1. ---> System.NotSupportedException: Deserialization of types without a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found