Skip to content

Fix custom bus event deserialization#318

Draft
hutiefang76 wants to merge 1 commit into
spring-cloud:mainfrom
hutiefang76:codex/bus-custom-event-deserialization
Draft

Fix custom bus event deserialization#318
hutiefang76 wants to merge 1 commit into
spring-cloud:mainfrom
hutiefang76:codex/bus-custom-event-deserialization

Conversation

@hutiefang76

Copy link
Copy Markdown

What changed

This updates the Bus JSON message converter so custom RemoteApplicationEvent subclasses are not deserialized through implicit public constructors.

With Jackson 3, a custom event constructor such as TestEvent(Object source, String originService, String destinationService, String key) can be selected as a property-based creator. The incoming JSON does not contain source, so Jackson passes null and ApplicationEvent rejects it with IllegalArgumentException: null source.

The Bus event model already provides no-arg constructors for deserialization. The converter now disables implicit creator/scalar-constructor visibility for its dedicated mapper, so custom events are instantiated through the default constructor and then populated from JSON properties.

Validation

  • Reproduced the failure with a custom TestEvent payload matching the report in Custom Event Cannot be Deserialized spring-cloud-stream#3162.
  • ./mvnw -pl spring-cloud-bus -Dtest=SubtypeModuleTests#testDeserializeCustomEventWithSimpleTypeName -Dstyle.color=never --no-transfer-progress test
  • ./mvnw -pl spring-cloud-bus -Dtest=SubtypeModuleTests,RemoteApplicationEventScanTests,BusAutoConfigurationTests -Dstyle.color=never --no-transfer-progress test
  • ./mvnw -pl spring-cloud-bus -Dstyle.color=never --no-transfer-progress test (77 tests, 0 failures/errors)
  • git diff --check

Addresses spring-cloud/spring-cloud-stream#3162.

Signed-off-by: hutiefang <hutiefang@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants