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(Element s)
Parses the given XML element into a value of type<T>
.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>
.default Serializer<T>
nullable()
Returns a decorated serializer that can handle null values.static <T> Serializer<T>
stringConversion(Function<String,T> fromString, Function<T,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 Map<T,V>>
Serializer<M>toMap(Supplier<M> emptyMapSupplier, Serializer<V> valueSerializer)
Builds a new serializer that can serialize maps with key type<T>
.default <C extends Collection<T>>
Serializer<C>toSeq(Supplier<C> emptyCollSupplier)
Builds a new serializer that can serialize arbitrary collections with element type<T>
.Element
toXml(T t, Supplier<Element> eltFactory)
Produce an XML element that represents the value [t].
-
-
-
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 byfromXml(Element)
.
-
fromXml
T fromXml(Element s)
Parses the given XML element into a value of type<T>
. This method must be kept in sync withtoXml(Object, Supplier)
.
-
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.
-
stringConversion
static <T> Serializer<T> stringConversion(Function<String,T> fromString, Function<T,String> toString)
Simple serialization from and to a string.
-
-