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.

When adding a extension to a builder it is not being serialized to the message

See original GitHub issue

https://github.com/cloudevents/sdk-java/blob/c85c691ea63516bfc7920ad4289ec1b6e267be4e/api/src/main/java/io/cloudevents/impl/DefaultCloudEventImpl.java#L36

When building a cloudEvent like below :

    final DistributedTracingExtension dte = new DistributedTracingExtension();
    dte.setTraceparent("00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01");
    dte.setTracestate("congo=BleGNlZWRzIHRohbCBwbGVhc3VyZS4");

    return new
        CloudEventBuilder<T>().contentType(ContentType.APPLICATION_JSON.getMimeType())
        .id("123")
        .time(ZonedDateTime.ofInstant(Instant.now(), ZoneOffset.UTC))
        .type("evType")
        .source("a.b.c")
        .data(entity)
        .extension(dte).build();

The extension is not being serialized when creating the json event.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

3reactions
pajomacommented, Jun 6, 2019

Any news on this? We need the extensions as well.

2reactions
razkevichcommented, Jul 4, 2019

We have found an easy workaround for this. So instead of doing this:

payloadAsString = io.cloudevents.json.Json.encode(cloudEvent);

we do this:

payloadAsString = io.cloudevents.json.Json.MAPPER.writerFor(CloudEvent.class).writeValueAsString(cloudEvent);

For some reason the latter results in a string which has extensions serialized in one of the resulting json fields

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serializing with Jackson (JSON) - getting "No serializer found"?
I solved it by adding this annotation for my child class whose object was to be serialized. @JsonAutoDetect(fieldVisibility = JsonAutoDetect ...
Read more >
Writing Your Own Extension - Quarkus
Quarkus extensions add a new developer focused behavior to the core offering, and consist of two distinct parts, buildtime augmentation and runtime ...
Read more >
Overview | Protocol Buffers - Google Developers
A map type, to add key-value pairs to your definition. In proto2, messages can allow extensions to define fields outside of the message,...
Read more >
Use MessagePack Hub Protocol in SignalR for ASP.NET Core
Adding MessagePack enables support for both JSON and MessagePack clients. ... Kind is not preserved when serializing/deserializing.
Read more >
Different Serialization Approaches for Java - Baeldung
There are some caveats that concern native serialization in Java: Only objects marked Serializable can be persisted. The Object class does not ...
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