Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for custom serializers/deserializers/adapters in a deterministic way #409

Merged
merged 1 commit into from
May 20, 2020

Conversation

aguibert
Copy link
Member

Fix for: quarkusio/quarkus#8925

Currently Yasson stores all custom components (where "component" can be a JsonbSerailizer/JsonbDeserializer/JsonbAdapter) in a map, and discovers a matching component for a given type by simply iterating over the values in the component map and returning the first match.
This has a few issues:

  1. The order we iterate over the component map is non-deterministic
  2. We may find a component that matches, but there are more specific matches available

For example, consider:

public class A {}
public class B extends A {}
public class C extends B {}
// Also assume that A/B/C have custom serializers

If a user wants to serialize a new B();, serializer's A or B would technically match, but serializer B would be the best choice because it is the closest match to the type being serialized.

The algorithm I'm proposing we use for matching is:

  1. Check for a component that exactly matches the type T
  2. Otherwise, iterate over all interfaces that type T implements and select the first matching interface
  3. Otherwise, if T has a superclass, repeat steps (1) and (2) until java.lang.Object is reached
  4. Otherwise, no match is found.

@aguibert aguibert added the bug Something isn't working right label May 14, 2020
@aguibert aguibert requested a review from Verdent May 14, 2020 18:01
@aguibert aguibert self-assigned this May 14, 2020
@aguibert
Copy link
Member Author

@Verdent can you please review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants