Class SerializationContext<T>

java.lang.Object
com.mrivanplays.annotationconfig.core.serialization.SerializationContext<T>
Type Parameters:
T - generic type of information that's being (de)serialized

public final class SerializationContext<T> extends Object
Represents a serialization context. This holds information about the Field that's being (de)serialized, but since AnnotationConfig can not always get a Field instance, this context class will hold information.
Since:
3.0.0
Author:
MrIvanPlays
  • Method Details

    • fromField

      public static <T> SerializationContext<T> fromField(Field field, Object annotatedConfig) throws IllegalAccessException
      Creates a new SerializationContext from a Field
      Type Parameters:
      T - type
      Parameters:
      field - field to create context from
      annotatedConfig - annotated config
      Returns:
      new serialization context
      Throws:
      IllegalAccessException - see Field.get(Object)
    • of

      public static <T> SerializationContext<T> of(Class<?> classType, Type genericType, Object annotatedConfig)
      Creates a new SerializationContext
      Type Parameters:
      T - type
      Parameters:
      classType - class type
      genericType - generic class type
      annotatedConfig - annotatedConfig
      Returns:
      new serialization context
    • of

      public static <T> SerializationContext<T> of(T def, Class<?> classType, Type genericType, Object annotatedConfig)
      Creates a new SerializationContext
      Type Parameters:
      T - type
      Parameters:
      def - default value. can be null
      classType - class type
      genericType - generic class type
      annotatedConfig - annotatedConfig
      Returns:
      new serialization context
    • of

      public static <T> SerializationContext<T> of(String name, T def, Class<?> classType, Type genericType, Object annotatedConfig)
      Creates a new SerializationContext
      Type Parameters:
      T - type
      Parameters:
      name - name of field. can be null
      def - default value. can be null
      classType - class type
      genericType - generic class type
      annotatedConfig - annotatedConfig
      Returns:
      new serialization context
    • getName

      public Optional<String> getName()
      Returns an Optional which may or may not be fulfilled with a name. In most of the cases, this is a field name.
      Returns:
      name or empty optional
    • getDefaultValue

      Returns an Optional which may or may not be fulfilled with a default value. In most of the cases, this is fulfilled.
      Returns:
      default value or empty optional
    • getClassType

      public Class<?> getClassType()
      Returns the Class type of the (de)serialized object.
      Returns:
      class type
    • getGenericType

      public Type getGenericType()
      Returns the generic Type of the (de)serialized object.
      Returns:
      generic type
    • getAnnotatedConfig

      Returns the annotated config this context originated from.
      Returns:
      annotated config