Class TypeAllowlist

java.lang.Object
dev.langchain4j.internal.TypeAllowlist

public class TypeAllowlist extends Object
Decides which types may be instantiated while reading JSON that carries type information.

JSON written with type information names the classes to instantiate, so reading it is a way to instantiate whatever the document asks for. An allowlist is what keeps that from being a way to instantiate anything on the classpath.

The decision is expressed here in terms of class names rather than in a JSON library's validator interface, so that every codec asks the same question of the same list.

  • Constructor Details

    • TypeAllowlist

      public TypeAllowlist()
      Starts with the JDK value types and LangChain4j's own data types, which any document may name. Everything else is up to the caller.
  • Method Details

    • addAllowedPrefix

      public void addAllowedPrefix(String prefix)
    • addAllowedClass

      public void addAllowedClass(String className)
    • isAllowedTypeId

      public boolean isAllowedTypeId(String typeId)
      Whether a type named in the document may be instantiated. An array type is judged by its element type.
    • isAlwaysAllowedType

      public boolean isAlwaysAllowedType(Class<?> rawClass)
      Whether a resolved type is one of the few always permitted regardless of the allowlist: primitives, boxed primitives, strings and enums.