Class PolymorphicTypes

java.lang.Object
dev.langchain4j.internal.PolymorphicTypes

public final class PolymorphicTypes extends Object
Detection and naming for polymorphic base types — sealed interfaces / classes (no annotations needed) and types annotated with Jackson's JsonSubTypes. Used by both schema generation and the Jackson polymorphic-dispatch hook for sealed types.
  • Field Details

    • DEFAULT_DISCRIMINATOR_PROPERTY

      public static final String DEFAULT_DISCRIMINATOR_PROPERTY
      Default discriminator property name when @JsonTypeInfo is not configured.
      See Also:
  • Method Details

    • isPolymorphic

      public static boolean isPolymorphic(Class<?> type)
      Returns true if type is a polymorphic base — sealed, or annotated with JsonSubTypes — and has at least one concrete subtype discoverable by langchain4j.
    • findConcreteSubtypes

      public static List<Class<?>> findConcreteSubtypes(Class<?> type)
      Concrete (instantiable) subtypes for type. Sealed hierarchies are flattened recursively; @JsonSubTypes on the base takes precedence over sealed permits.
    • discriminatorPropertyName

      public static String discriminatorPropertyName(Class<?> baseType)
      Discriminator property name. Honors @JsonTypeInfo(property=...) when explicit; otherwise "@type" for @JsonTypeInfo-annotated bases (Jackson's default) and DEFAULT_DISCRIMINATOR_PROPERTY otherwise.
    • discriminatorValue

      public static String discriminatorValue(Class<?> baseType, Class<?> subtype)
      Discriminator value for a subtype. Resolution order: @JsonSubTypes.Type(name=...) on the base → @JsonTypeName on the subtype → Class.getSimpleName().
    • verifyJsonTypeInfoIsSupported

      public static void verifyJsonTypeInfoIsSupported(Class<?> baseType)
      Verifies that the @JsonTypeInfo configuration on baseType (if present) uses settings supported by langchain4j. Throws otherwise so the user gets a clear failure at schema-generation time rather than a silent mismatch.

      Supported use: Id.NAME, Id.SIMPLE_NAME.
      Supported include: As.PROPERTY, As.EXISTING_PROPERTY.