Interface TypeInformation<S>

All Known Implementing Classes:
ClassTypeInformation

public interface TypeInformation<S>
Interface to access property types and resolving generics on the way. Starting with a ClassTypeInformation you can traverse properties using getProperty(String) to access type information.
Author:
Oliver Gierke, Mark Paluch, Alessandro Nistico, Johannes Englmeier, Christoph Strobl
  • Field Details

  • Method Details

    • orObject

      static TypeInformation<?> orObject(@Nullable ResolvableType type)
    • of

      static TypeInformation<?> of(ResolvableType type)
      Creates a new TypeInformation from the given ResolvableType.
      Parameters:
      type - must not be null.
      Returns:
      will never be null.
      Since:
      3.0
    • of

      static <S> TypeInformation<S> of(Class<S> type)
      Creates a new TypeInformation for the given Class.
      Parameters:
      type - must not be null.
      Returns:
      will never be null.
      Since:
      3.0
    • fromReturnTypeOf

      static TypeInformation<?> fromReturnTypeOf(Method method)
      Returns a TypeInformation for the given Method.
      Parameters:
      method - must not be null.
      Returns:
      will never be null.
      Since:
      3.0
    • fromReturnTypeOf

      static TypeInformation<?> fromReturnTypeOf(Method method, @Nullable Class<?> type)
      Returns a TypeInformation for the given method as declared on the given type.
      Parameters:
      method - must not be null.
      type - can be null.
      Returns:
      will never be null.
      Since:
      3.0
    • fromMethodParameter

      static TypeInformation<?> fromMethodParameter(MethodParameter parameter)
      Returns a new TypeInformation for the given MethodParameter.
      Parameters:
      parameter - must not be null.
      Returns:
      will never be null.
      Since:
      3.0
    • getParameterTypes

      List<TypeInformation<?>> getParameterTypes(Constructor<?> constructor)
      Returns the TypeInformations for the parameters of the given Constructor.
      Parameters:
      constructor - must not be null.
      Returns:
    • getProperty

      @Nullable TypeInformation<?> getProperty(String property)
      Returns the property information for the property with the given name. Supports property traversal through dot notation.
      Parameters:
      property -
      Returns:
    • getRequiredProperty

      default TypeInformation<?> getRequiredProperty(String property)
      Returns the property information for the property with the given name or throw IllegalArgumentException if the type information cannot be resolved. Supports property traversal through dot notation.
      Parameters:
      property -
      Returns:
      Throws:
      IllegalArgumentException - if the type information cannot be resolved.
      Since:
      2.0
    • isCollectionLike

      boolean isCollectionLike()
      Returns whether the type can be considered a collection, which means it's a container of elements, e.g. a Collection and Array or anything implementing Iterable. If this returns true you can expect getComponentType() to return a non-null value.
      Returns:
    • getComponentType

      @Nullable TypeInformation<?> getComponentType()
      Returns the component type for Collections or the key type for Maps.
      Returns:
    • getRequiredComponentType

      default TypeInformation<?> getRequiredComponentType()
      Returns the component type for Collections, the key type for Maps or the single generic type if available. Throws IllegalStateException if the component value type cannot be resolved.
      Returns:
      Throws:
      IllegalStateException - if the component type cannot be resolved, e.g. if a raw type is used or the type is not generic in the first place.
      Since:
      2.0
    • isMap

      boolean isMap()
      Returns whether the property is a Map. If this returns true you can expect getComponentType() as well as getMapValueType() to return something not null.
      Returns:
    • getMapValueType

      @Nullable TypeInformation<?> getMapValueType()
      Will return the type of the value in case the underlying type is a Map.
      Returns:
    • getRequiredMapValueType

      default TypeInformation<?> getRequiredMapValueType()
      Will return the type of the value in case the underlying type is a Map or throw IllegalStateException if the map value type cannot be resolved.
      Returns:
      Throws:
      IllegalStateException - if the map value type cannot be resolved, usually due to the current Map type being a raw one.
      Since:
      2.0
    • getType

      Class<S> getType()
      Returns the type of the property. Will resolve generics and the generic context of
      Returns:
    • getUserTypeInformation

      default TypeInformation<?> getUserTypeInformation()
      Returns the user type of the property if proxied.
      Returns:
      the unpacked (if proxied) type of the property.
      Since:
      2.6
      See Also:
    • getRawTypeInformation

      ClassTypeInformation<?> getRawTypeInformation()
      Returns a ClassTypeInformation to represent the TypeInformation of the raw type of the current instance.
      Returns:
    • getActualType

      @Nullable TypeInformation<?> getActualType()
      Transparently returns the Map value type if the type is a Map, returns the component type if the type isCollectionLike() or the simple type if none of this applies.
      Returns:
      the map value, collection component type or the current type, null it the current type is a raw Map or Collection.
    • getRequiredActualType

      default TypeInformation<?> getRequiredActualType()
      Transparently returns the Map value type if the type is a Map, returns the component type if the type isCollectionLike() or the simple type if none of this applies.
      Returns:
      Throws:
      IllegalArgumentException - if the current type is a raw Map or Collection and no value or component type is available.
      Since:
      2.0
    • getReturnType

      TypeInformation<?> getReturnType(Method method)
      Returns a TypeInformation for the return type of the given Method. Will potentially resolve generics information against the current types type parameter bindings.
      Parameters:
      method - must not be null.
      Returns:
    • getParameterTypes

      List<TypeInformation<?>> getParameterTypes(Method method)
      Returns the TypeInformations for the parameters of the given Method.
      Parameters:
      method - must not be null.
      Returns:
    • getSuperTypeInformation

      @Nullable TypeInformation<?> getSuperTypeInformation(Class<?> superType)
      Returns the TypeInformation for the given raw super type.
      Parameters:
      superType - must not be null.
      Returns:
      the TypeInformation for the given raw super type or null in case the current TypeInformation does not implement the given type.
    • getRequiredSuperTypeInformation

      default TypeInformation<?> getRequiredSuperTypeInformation(Class<?> superType)
      Returns the TypeInformation for the given raw super type.
      Parameters:
      superType - must not be null.
      Returns:
      the TypeInformation for the given raw super type.
      Throws:
      IllegalArgumentException - in case the current TypeInformation does not implement the given type.
      Since:
      2.0
    • isAssignableFrom

      boolean isAssignableFrom(TypeInformation<?> target)
      Returns if the current TypeInformation can be safely assigned to the given one. Mimics semantics of Class.isAssignableFrom(Class) but takes generics into account. Thus it will allow to detect that a List<Long> is assignable to List<? extends Number>.
      Parameters:
      target -
      Returns:
    • getTypeArguments

      List<TypeInformation<?>> getTypeArguments()
      Returns the TypeInformation for the type arguments of the current TypeInformation.
      Returns:
    • specialize

      @Deprecated default TypeInformation<? extends S> specialize(ClassTypeInformation<?> type)
      Deprecated.
      since 3.0. Use specialize(TypeInformation) instead, i.e. switch the given parameter's type to TypeInformation in the first place.
      Specializes the given (raw) ClassTypeInformation using the context of the current potentially parameterized type, basically turning the given raw type into a parameterized one. Will return the given type as is if no generics are involved.
      Parameters:
      type - must not be null.
      Returns:
      will never be null.
    • specialize

      default TypeInformation<? extends S> specialize(TypeInformation<?> type)
      Specializes the given (raw) TypeInformation using the context of the current potentially parameterized type, basically turning the given raw type into a parameterized one. Will return the given type as is if no generics are involved.
      Parameters:
      type - must not be null.
      Returns:
      will never be null.
    • isSubTypeOf

      default boolean isSubTypeOf(Class<?> type)
      Returns whether the current type is a sub type of the given one, i.e. whether it's assignable but not the same one.
      Parameters:
      type - must not be null.
      Returns:
      Since:
      2.2
    • toTypeDescriptor

      TypeDescriptor toTypeDescriptor()
      Returns the TypeDescriptor equivalent of this TypeInformation.
      Returns:
      will never be null.
      Since:
      2.7