cloudevents / cloudevents/sdk-java
Unable to serialize complex (custom) extension in the expected json format
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 446
- Forks
- 172
- PR merge metrics
- No merged PRs in 30d
Description
creating a custom extension object implementing CloudEventExtension, when using the extension (customExt) as below, and then serializing the CloudEvent, the serialization for the CloudEvent is failing with JsonMappingException.
CloudEventBuilder.v1()
.withSource(URI.create(source))
.withType(event_type)
.withTime(event_time)
.withId(event.getEventId())
.withDataContentType(contentType)
.withData(eventPayaload)
.withDataSchema(URI.create(XDM_SCHEMA_URI))
.withExtension(DATA_SCHEMA_VERSION_KEY_EXTENSION_NAME, schemaVerExt)
.withExtension(X_ACTION_ID_KEY_EXTENSION_NAME, requestIdExt)
.withExtension(customExt);
here is how the extension looks like. The customExt is the Recipient object
Also, if using the other supported methods withExtension (with key, value) as below, I had to send the string version of the customExt, and then if serialized the output is not in the expected format (see below). It can break our customers event
integrations. Kindly suggest.
expected serialized CloudEvent custom extension
"recipient":{"userid":"9CE048DB5E8F485XXXXXXXXX@AdobeOrg"}
actual serialized CloudEvent custom extension
"recipient":"{\"userid\":\"9CE048DB5E8F485XXXXXXXXX@AdobeOrg\"}"
The serialization is failing while reading extensions here, as I believe the Object type value is not supported.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at core/src/main/java/io/cloudevents/core/impl/BaseCloudEvent.java around line 84, where extension values are read during serialization. Reproduce the issue with the custom Recipient extension and the withExtension overloads shown in the report, then compare the serialized output with the expected nested recipient JSON. Done means custom extension objects serialize without JsonMappingException and are not emitted as escaped JSON strings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100