Skip to content

Find union members and interface implementors from @JsonSubTypes #862

Open

Description

@oryan-block

Follow-up to #200 and #854. #854 only helps when the class behind a union or interface is sealed. For plain hierarchies you still need a dictionary entry per member.

A lot of these classes already list their subtypes for Jackson:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "__typename")
@JsonSubTypes(
    JsonSubTypes.Type(value = MemberA::class, name = "MemberA"),
    JsonSubTypes.Type(value = MemberB::class, name = "MemberB"))
interface AnyMember

@briankrug's patch reads that annotation in SchemaClassScanner and matches each subtype to an object type by JsonSubTypes.Type#name.

Main issue is, the JSON type name isn't the GraphQL type name. It defaults to "", and it makes a serialization annotation part of the schema mapping. Probably safer to use @JsonSubTypes only as the list of candidates and match on the class simpleName, same as the sealed lookup. It's the only route for non-sealed classes on Java 11 though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions