Class TypeSerializerCollection.Builder

  • Enclosing class:
    TypeSerializerCollection

    public static class TypeSerializerCollection.Builder
    extends java.lang.Object
    A builder to construct new serializer collections.

    Serializers added to a builder will be prioritized based on registration order, so if multiple serializers could match a single type, the first-registered one will be used.

    Since:
    4.0.0
    • Method Detail

      • register

        public <T> TypeSerializerCollection.Builder register​(io.leangen.geantyref.TypeToken<T> type,
                                                             TypeSerializer<? super T> serializer)
        Register a type serializer for a given type.

        Serializers registered will match all subclasses of the provided type, as well as unwrapped primitive equivalents of the type.

        Type Parameters:
        T - the type to generify around
        Parameters:
        type - the type to accept
        serializer - the serializer that will be serialized with
        Returns:
        this builder
        Since:
        4.0.0
      • register

        public <T> TypeSerializerCollection.Builder register​(java.lang.Class<T> type,
                                                             TypeSerializer<? super T> serializer)
        Register a type serializer for a given type.

        Serializers registered will match all subclasses of the provided type, as well as unboxed primitive equivalents of the type.

        Type Parameters:
        T - the type to generify around
        Parameters:
        type - the type to accept
        serializer - the serializer that will be serialized with
        Returns:
        this builder
        Since:
        4.0.0
      • register

        public <T> TypeSerializerCollection.Builder register​(java.util.function.Predicate<java.lang.reflect.Type> test,
                                                             TypeSerializer<? super T> serializer)
        Register a type serializer matching against a given predicate.
        Type Parameters:
        T - the type parameter
        Parameters:
        test - the predicate to match types against
        serializer - the serializer to serialize matching types with
        Returns:
        this builder
        Since:
        4.0.0
      • register

        public <T> TypeSerializerCollection.Builder register​(ScalarSerializer<T> serializer)
        Register a scalar serializer with its own attached type token.

        Serializers registered will match all subclasses of the provided type, as well as unboxed primitive equivalents of the type.

        Type Parameters:
        T - value type
        Parameters:
        serializer - serializer to register
        Returns:
        this builder
        Since:
        4.0.0
      • registerAnnotated

        public <T> TypeSerializerCollection.Builder registerAnnotated​(java.util.function.Predicate<java.lang.reflect.AnnotatedType> test,
                                                                      TypeSerializer<? super T> serializer)
        Register a type serializer matching against a given predicate, with type annotation information.
        Type Parameters:
        T - the type parameter
        Parameters:
        test - the predicate to match annotated types against
        serializer - the serializer to serialize matching types with
        Returns:
        this builder
        Since:
        4.2.0
        See Also:
        TypeSerializer.Annotated
      • registerExact

        public <T> TypeSerializerCollection.Builder registerExact​(io.leangen.geantyref.TypeToken<T> type,
                                                                  TypeSerializer<? super T> serializer)
        Register an exact type serializer for a given type.

        Serializers will only match exact object types. For example, a serializer registered for List<String> would not match when ArrayList<String> is queried.

        Type Parameters:
        T - the type to generify around
        Parameters:
        type - the type to accept
        serializer - the serializer that will be serialized with
        Returns:
        this builder
        Since:
        4.0.0
      • registerExact

        public <T> TypeSerializerCollection.Builder registerExact​(java.lang.Class<T> type,
                                                                  TypeSerializer<? super T> serializer)
        Register an exact type serializer for a given type.

        Serializers will only match exact object types. For example, a serializer registered for List<String> would not match when ArrayList<String> is queried.

        Type Parameters:
        T - the type to generify around
        Parameters:
        type - the type to accept
        serializer - the serializer that will be serialized with
        Returns:
        this builder
        Since:
        4.0.0
      • registerExact

        public <T> TypeSerializerCollection.Builder registerExact​(ScalarSerializer<T> serializer)
        Register a scalar serializer with its own attached type token.

        Serializers will only match exact object types. For example, a serializer registered for List<String> would not match when ArrayList<String> is queried.

        Type Parameters:
        T - value type
        Parameters:
        serializer - serializer to register
        Returns:
        this builder
        Since:
        4.0.0
      • registerAll

        public TypeSerializerCollection.Builder registerAll​(TypeSerializerCollection other)
        Register all serializers from other into this collection.

        Creating a child collection should be preferred, but when merging multiple sets of serializers together, directly adding other collections may be the best choice.

        Parameters:
        other - source collection
        Returns:
        this builder
        Since:
        4.0.0