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

Functionality for registering and finding contextual serializers for third party generic classes is incomplete. #1407

Closed
mvdbos opened this issue Apr 6, 2021 · 0 comments
Labels

Comments

@mvdbos
Copy link
Contributor

mvdbos commented Apr 6, 2021

These might possibly be bugs, but determining how to solve them requires a design discussion.

Summary

The use case here is serializing a third party generic class with different contents: ThirdPartyBox.
As is show in the manual, the BoxSerializer in this test is capable of serializing any ThirdPartyBox and takes as its constructor arg the serializer for T.

Different from the examples for generics in the manual, we have to use contextual here, because we don't control ThirdPartyBox.

Registering bug

Unfortunately, registering another contextual serializer for the generic BoxSerializer fails, because SerializersModuleBuilders.registerSerializer() only looks at the toplevel type of generic types to determine if a serializer was already registered.

See #1406 for details. That PR contains only a test showing the issue.

Finding bug

Finding the serializer for a (generic) third party type by KType fails, because SerializersModule.serializerByKTypeImpl()
never tries getContextual() after constructSerializerForGivenTypeArgs() fails to find a serializer (and that will fail, because ThirdPartyBox is not annotated as @serializable, since it is a third party class).

This does work when doing the look up by Java type with serializerByJavaTypeImpl.serializerByJavaTypeImpl().

See #1397 for details. That PR contains a solution to be discussed, and tests to support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant