Skip to content

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

Closed
@mvdbos

Description

@mvdbos

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions