Interface Serializer<T>

  • Type Parameters:
    T - Type of value handled

    public interface Serializer<T>
    Converts a value of type <T> to and from an XML element.
    • Method Detail

      • toXml

        Element toXml​(T t,
                      Supplier<Element> eltFactory)
        Produce an XML element that represents the value [t]. The parameter [eltFactory] can be used to produce a new element to add children. The returned element must be understood by fromXml(Element).
      • map

        default <S> Serializer<S> map​(Function<T,​S> toS,
                                      Function<S,​T> fromS)
        Returns a new serializer that can handle another type <S>, provided <T> can be mapped to and from <S>.
      • toArray

        default Serializer<T[]> toArray​(T[] emptyArray)
        Builds a new serializer that can serialize arrays of component type <T>.
        Parameters:
        emptyArray - Empty array supplier
        Returns:
        A new serializer
      • toMap

        default <V,​M extends Map<T,​V>> Serializer<M> toMap​(Supplier<M> emptyMapSupplier,
                                                                       Serializer<V> valueSerializer)
        Builds a new serializer that can serialize maps with key type <T>.
        Type Parameters:
        M - Map type to serialize
        Parameters:
        emptyMapSupplier - Supplier for a collection of the correct type, to which the deserialized elements are added.
        Returns:
        A new serializer
      • toSeq

        default <C extends Collection<T>> Serializer<C> toSeq​(Supplier<C> emptyCollSupplier)
        Builds a new serializer that can serialize arbitrary collections with element type <T>.
        Type Parameters:
        C - Collection type to serialize
        Parameters:
        emptyCollSupplier - Supplier for a collection of the correct type, to which the deserialized elements are added.
        Returns:
        A new serializer
      • nullable

        default Serializer<T> nullable()
        Returns a decorated serializer that can handle null values. Standard serializer combinators already all return a nullable serializer. This method returns this if it's already nullable.