Skip to content

Handle Structured CloudEvent binary payload convertion - #1460

Open
radhakrishnan10192 wants to merge 1 commit into
spring-cloud:mainfrom
radhakrishnan10192:bugfix/cloud-event-structured-flow
Open

Handle Structured CloudEvent binary payload convertion#1460
radhakrishnan10192 wants to merge 1 commit into
spring-cloud:mainfrom
radhakrishnan10192:bugfix/cloud-event-structured-flow

Conversation

@radhakrishnan10192

Copy link
Copy Markdown

Fixes #1455

Problem

When a structured-mode CloudEvent (Content-Type: application/cloudevents+json, whole envelope in the body) is consumed by a function whose target type is the CNCF
io.cloudevents.CloudEvent, conversion fails.

CloudEventMessageUtils.toCanonical(...) transforms the structured message into a binary-shaped message (data extracted into the payload, attributes moved to ce-* headers), but
the resulting message is left in an inconsistent state:

  1. Content-type isn't reset — the message still says application/cloudevents+json even though the payload is no longer the serialized envelope.
  2. data is left as a deserialized Map, not serialized bytes.

Downstream, io.cloudevents.spring.messaging.CloudEventMessageConverter re-decides structured-vs-binary purely from contentType. Because the stale application/cloudevents+json
remains, it selects the structured reader and tries to re-parse the already-extracted payload as the envelope:

io.cloudevents.rw.CloudEventRWException: Could not parse. Unknown encoding. Invalid content type or spec version                                                               
       at io.cloudevents.core.message.impl.MessageUtils.parseStructuredOrBinaryMessage(MessageUtils.java:69)                                                                    
       at io.cloudevents.spring.messaging.CloudEventMessageConverter.fromMessage(CloudEventMessageConverter.java:45)                                                            
       at ...SmartCompositeMessageConverter.fromMessage(...)                                                                                                                    
                                                                                                              
and 

java.lang.IllegalArgumentException: argument "src" is null
   at io.cloudevents.jackson.JsonFormat.deserialize(JsonFormat.java:158)
   at io.cloudevents.spring.messaging.CloudEventMessageConverter.fromMessage(CloudEventMessageConverter.java:45)
   at org.springframework.cloud.function.context.config.SmartCompositeMessageConverter.fromMessage(...)
   at ...SimpleFunctionRegistry$FunctionInvocationWrapper.convertInputMessageIfNecessary(...)
                                                                 

This only affects the io.cloudevents.CloudEvent target type. A plain POJO target works because Spring's own converters can bind a Map payload to a POJO, which is why the existing tests didn't catch it.

Signed-off-by: radhakrishnan <radhakrishnan@paypal.com>
@radhakrishnan10192
radhakrishnan10192 force-pushed the bugfix/cloud-event-structured-flow branch from f35f402 to c489503 Compare September 3, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Structured CloudEvent fails to convert to io.cloudevents.CloudEvent in the functional model (data lost / "Unknown encoding")

1 participant