Interface TypeSerializer<T>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  TypeSerializer.Annotated<V>
      A type serializer that prefers type use annotation metadata to deserialize the type.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default T deserialize​(java.lang.reflect.AnnotatedType type, ConfigurationNode node)
      Deserialize an object (of the correct type) from the given configuration node.
      T deserialize​(java.lang.reflect.Type type, ConfigurationNode node)
      Deserialize an object (of the correct type) from the given configuration node.
      default @Nullable T emptyValue​(java.lang.reflect.AnnotatedType specificType, ConfigurationOptions options)
      Create an empty value of the appropriate type.
      default @Nullable T emptyValue​(java.lang.reflect.Type specificType, ConfigurationOptions options)
      Create an empty value of the appropriate type.
      static <T> ScalarSerializer<T> of​(java.lang.Class<T> type, java.util.function.BiFunction<T,​java.util.function.Predicate<java.lang.Class<?>>,​java.lang.Object> serializer, CheckedFunction<java.lang.Object,​T,​SerializationException> deserializer)
      Given the provided functions, create a new serializer for a scalar value.
      static <T> ScalarSerializer<T> of​(java.lang.reflect.Type type, java.util.function.BiFunction<T,​java.util.function.Predicate<java.lang.Class<?>>,​java.lang.Object> serializer, CheckedFunction<java.lang.Object,​T,​SerializationException> deserializer)
      Given the provided functions, create a new serializer for a scalar value.
      default void serialize​(java.lang.reflect.AnnotatedType type, @Nullable T obj, ConfigurationNode node)
      Serialize an object to the given configuration node.
      void serialize​(java.lang.reflect.Type type, @Nullable T obj, ConfigurationNode node)
      Serialize an object to the given configuration node.
    • Method Detail

      • of

        static <T> ScalarSerializer<T> of​(java.lang.reflect.Type type,
                                          java.util.function.BiFunction<T,​java.util.function.Predicate<java.lang.Class<?>>,​java.lang.Object> serializer,
                                          CheckedFunction<java.lang.Object,​T,​SerializationException> deserializer)
        Given the provided functions, create a new serializer for a scalar value.

        The returned serializer must fulfill all the requirements of a ScalarSerializer

        Type Parameters:
        T - the type of value to deserialize
        Parameters:
        type - the type of value returned by the serializer
        serializer - the serialization function, implementing ScalarSerializer.serialize(Object, Predicate)
        deserializer - the deserialization function, implementing ScalarSerializer.deserialize(Type, Object)
        Returns:
        a new and unregistered type serializer
        Since:
        4.0.0
      • deserialize

        default T deserialize​(java.lang.reflect.AnnotatedType type,
                              ConfigurationNode node)
                       throws SerializationException
        Deserialize an object (of the correct type) from the given configuration node.
        Parameters:
        type - the annotated type of return value required
        node - the node containing serialized data
        Returns:
        an object
        Throws:
        SerializationException - if the presented data is invalid
        Since:
        4.2.0
      • deserialize

        T deserialize​(java.lang.reflect.Type type,
                      ConfigurationNode node)
               throws SerializationException
        Deserialize an object (of the correct type) from the given configuration node.
        Parameters:
        type - the type of return value required
        node - the node containing serialized data
        Returns:
        an object
        Throws:
        SerializationException - if the presented data is invalid
        Since:
        4.0.0
      • serialize

        default void serialize​(java.lang.reflect.AnnotatedType type,
                               @Nullable T obj,
                               ConfigurationNode node)
                        throws SerializationException
        Serialize an object to the given configuration node.
        Parameters:
        type - the annotated type of the input object
        obj - the object to be serialized
        node - the node to write to
        Throws:
        SerializationException - if the object cannot be serialized
        Since:
        4.2.0
      • serialize

        void serialize​(java.lang.reflect.Type type,
                       @Nullable T obj,
                       ConfigurationNode node)
                throws SerializationException
        Serialize an object to the given configuration node.
        Parameters:
        type - the type of the input object
        obj - the object to be serialized
        node - the node to write to
        Throws:
        SerializationException - if the object cannot be serialized
        Since:
        4.0.0
      • emptyValue

        default @Nullable T emptyValue​(java.lang.reflect.Type specificType,
                                       ConfigurationOptions options)
        Create an empty value of the appropriate type.

        This method is for the most part designed to create empty collection types, though it may be useful for scalars in limited cases.

        Parameters:
        specificType - specific subtype to create an empty value of
        options - options used from the loading node
        Returns:
        new empty value
        Since:
        4.0.0
      • emptyValue

        default @Nullable T emptyValue​(java.lang.reflect.AnnotatedType specificType,
                                       ConfigurationOptions options)
        Create an empty value of the appropriate type.

        This method is for the most part designed to create empty collection types, though it may be useful for scalars in limited cases.

        Parameters:
        specificType - specific annotated subtype to create an empty value of
        options - options used from the loading node
        Returns:
        new empty value
        Since:
        4.2.0