Record Class DelegateTypeAdapterFactory

java.lang.Object
java.lang.Record
eu.cloudnetservice.driver.impl.document.gson.DelegateTypeAdapterFactory
Record Components:
typeSupportChecker - the check predicate if a type is supported by this factory.
delegateFactory - the delegated function to construct the actual type adapter.
All Implemented Interfaces:
com.google.gson.TypeAdapterFactory

record DelegateTypeAdapterFactory(@NonNull Predicate<Class<?>> typeSupportChecker, @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory) extends Record implements com.google.gson.TypeAdapterFactory
A type adapter factory implementation that first validates that the correct type can be provided by it and then calls the given delegate function, passing the target gson instance to it.
Since:
4.0
  • Field Details

  • Constructor Details

    • DelegateTypeAdapterFactory

      DelegateTypeAdapterFactory(@NonNull @NonNull Predicate<Class<?>> typeSupportChecker, @NonNull @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory)
      Creates an instance of a DelegateTypeAdapterFactory record class.
      Parameters:
      typeSupportChecker - the value for the typeSupportChecker record component
      delegateFactory - the value for the delegateFactory record component
  • Method Details

    • standardFactory

      @NonNull public static @NonNull com.google.gson.TypeAdapterFactory standardFactory(@NonNull @NonNull Class<?> baseClass, @NonNull @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory)
      Constructs a new factory that validates that the requested type is exactly the given base type before calling the delegate function.
      Parameters:
      baseClass - the base class that the requested type must be equal to.
      delegateFactory - the delegate factory to call when a type factory should be created.
      Returns:
      a type adapter factory that validates that the exact type is requested before constructing the adapter.
      Throws:
      NullPointerException - if the given base type or delegate factory is null.
    • hierarchyFactory

      @NonNull public static @NonNull com.google.gson.TypeAdapterFactory hierarchyFactory(@NonNull @NonNull Class<?> baseClass, @NonNull @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory)
      Constructs a new factory that validates that the requested type is somewhere in the hierarchy of the given base type before calling the delegate function.
      Parameters:
      baseClass - the base class that the requested type must be in the hierarchy of.
      delegateFactory - the delegate factory to call when a type factory should be created.
      Returns:
      a type adapter factory that validates that a hierarchy type is requested before constructing the adapter.
      Throws:
      NullPointerException - if the given base type or delegate factory is null.
    • create

      @Nullable public <T> @Nullable com.google.gson.TypeAdapter<T> create(@NonNull @NonNull com.google.gson.Gson gson, @NonNull @NonNull com.google.gson.reflect.TypeToken<T> type)
      Specified by:
      create in interface com.google.gson.TypeAdapterFactory
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • typeSupportChecker

      @NonNull public @NonNull Predicate<Class<?>> typeSupportChecker()
      Returns the value of the typeSupportChecker record component.
      Returns:
      the value of the typeSupportChecker record component
    • delegateFactory

      @NonNull public @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory()
      Returns the value of the delegateFactory record component.
      Returns:
      the value of the delegateFactory record component