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 Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      T fromXml​(org.w3c.dom.Element s)
      Parses the given XML element into a value of type <T>.
      default <S> Serializer<S> map​(java.util.function.Function<T,​S> toS, java.util.function.Function<S,​T> fromS)
      Returns a new serializer that can handle another type <S>, provided <T> can be mapped to and from <S>.
      default Serializer<T> nullable()
      Returns a decorated serializer that can handle null values.
      static <T> Serializer<T> stringConversion​(java.util.function.Function<java.lang.String,​T> fromString, java.util.function.Function<T,​java.lang.String> toString)
      Simple serialization from and to a string.
      default Serializer<T[]> toArray​(T[] emptyArray)
      Builds a new serializer that can serialize arrays of component type <T>.
      default <V,​M extends java.util.Map<T,​V>>
      Serializer<M>
      toMap​(java.util.function.Supplier<M> emptyMapSupplier, Serializer<V> valueSerializer)
      Builds a new serializer that can serialize maps with key type <T>.
      default <C extends java.util.Collection<T>>
      Serializer<C>
      toSeq​(java.util.function.Supplier<C> emptyCollSupplier)
      Builds a new serializer that can serialize arbitrary collections with element type <T>.
      org.w3c.dom.Element toXml​(T t, java.util.function.Supplier<org.w3c.dom.Element> eltFactory)
      Produce an XML element that represents the value [t].
    • Method Detail

      • toXml

        org.w3c.dom.Element toXml​(T t,
                                  java.util.function.Supplier<org.w3c.dom.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).
      • fromXml

        T fromXml​(org.w3c.dom.Element s)
        Parses the given XML element into a value of type <T>. This method must be kept in sync with toXml(Object, Supplier).
      • map

        default <S> Serializer<S> map​(java.util.function.Function<T,​S> toS,
                                      java.util.function.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 java.util.Map<T,​V>> Serializer<M> toMap​(java.util.function.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 java.util.Collection<T>> Serializer<C> toSeq​(java.util.function.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.
      • stringConversion

        static <T> Serializer<T> stringConversion​(java.util.function.Function<java.lang.String,​T> fromString,
                                                  java.util.function.Function<T,​java.lang.String> toString)
        Simple serialization from and to a string.