Fix custom bus event deserialization#318
Draft
hutiefang76 wants to merge 1 commit into
Draft
Conversation
Signed-off-by: hutiefang <hutiefang@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
This updates the Bus JSON message converter so custom
RemoteApplicationEventsubclasses 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 containsource, so Jackson passesnullandApplicationEventrejects it withIllegalArgumentException: 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
TestEventpayload 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 --checkAddresses spring-cloud/spring-cloud-stream#3162.