You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request introduces a flexible mechanism for dynamically selecting custom serializers in the Serializer system based on user-defined predicates. This enables feature-specific serializers (such as for Java Records) to be registered and automatically applied to matching classes without modifying the engine core. It also includes comprehensive tests to verify the new predicate-based serializer registration and routing logic. Additionally, there are minor bug fixes and improvements in message reliability handling.
Serializer predicate-based extension:
Introduced a registerSerializerPredicate(Predicate<Class<?>>, Serializer) method in Serializer to allow registering custom serializers that are selected for classes matching a given predicate. This enables dynamic, feature-specific serializer selection without hardcoding logic into the engine
Added a new test class PredicateSerializerTest that verifies:
Predicate-based serializers override the default for matching classes.
Non-matching classes fall back to the default FieldSerializer.
Predicate-based serializers are correctly used during auto-registration fallback.
The method parameter is named cls, so @param clazz is invalid. The Javadoc validation command in .github/workflows/main.yml enables -Xdoclint:all,-missing and -Werror through common.gradle, so this causes that task to fail. Rename the tag to match the parameter.
Record serialization support is definitely useful, but I don't think we should merge this implementation into the core just yet, mainly because:
Changing the default serializer in the @Serializable annotation is a breaking change.
This PR introduces quite a bit of reflection and complexity for a language feature that isn't supported by our current target Java version (Java 8, soon moving to Java 11).
I'd suggest reducing the scope of this PR to the minimum, backward-compatible changes needed to allow record serialization, while keeping the actual RecordSerializer implementation outside the PR for now. Developers who need it, can register it from their application.
Specifically, I'd keep two changes:
Keep the m = m.setReliable(reliable); changes in the networking adapters
Introduce predicate-based serializer selection: Add a generic mechanism to register a Predicate<Class<?>> alongside a Serializer, allowing custom serializers to be selected automatically based on the target class.
For example, applications running on Java 16+ could register their own RecordSerializer using Class::isRecord as the predicate, instead of having record-specific reflective detection hardcoded into the core.
This would also be useful beyond records, as other serializers could use the same mechanism to support different kinds of classes.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the PR to focus on the lightweight predicate-based serializer selection mechanism and networking adapter updates!
The predicate-based registration approach is clean and flexible for application-level custom serializers.
One fix is needed in Serializer.java: @Serializable defaults to FieldSerializer.class, which causes annotated classes to bypass predicate selection. Restricting the annotation check to explicit non-default serializers allows registered predicates to evaluate correctly.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for rescoping this — the predicate-based selection is now a small, backward-compatible addition, and the record-specific machinery is out of the PR as suggested.
The registerSerializerPredicate(Predicate<Class<?>>, Serializer) API is a clean, generic extension point that applications (including Java 16+ record support) can build on without core changes.
My earlier concern is addressed: classes with the default @Serializable serializer no longer short-circuit the predicate checks, and explicit custom serializers still win.
The m = m.setReliable(reliable) fixes in both adapters are correct for immutable message implementations.
Tests cover predicate override, non-matching fallback, and the auto-registration path nicely.
One thing worth adding to the registerSerializerPredicate Javadoc: matches are evaluated in registration order with first-match-wins, and predicates only affect classes registered afterwards — that ordering behavior is easy to trip over.
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
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.
This pull request introduces a flexible mechanism for dynamically selecting custom serializers in the
Serializersystem based on user-defined predicates. This enables feature-specific serializers (such as for Java Records) to be registered and automatically applied to matching classes without modifying the engine core. It also includes comprehensive tests to verify the new predicate-based serializer registration and routing logic. Additionally, there are minor bug fixes and improvements in message reliability handling.Serializer predicate-based extension:
Introduced a
registerSerializerPredicate(Predicate<Class<?>>, Serializer)method inSerializerto allow registering custom serializers that are selected for classes matching a given predicate. This enables dynamic, feature-specific serializer selection without hardcoding logic into the engineAdded a new test class
PredicateSerializerTestthat verifies:FieldSerializer.