public class StringSerializer<T> extends Object implements Serializer<T>
StringDeserializer should be used as the corresponding Deserializer.
| Modifier and Type | Method and Description |
|---|---|
static Serializer<String> |
create()
Retrieves an instance of this serializer directly serializing strings.
|
static <T> Serializer<T> |
create(Function<T,String> toString)
Retrieves an instance of this serializer.
|
byte[] |
serialize(T item)
Serializes an object to an array of byte.
|
public byte[] serialize(T item)
SerializerAny instance of T must be accepted and have a non null return value:
for any o, o instanceof T implies serialize(o) != null.
The output must be consistent, an identical output should be returned if called twice on the equal
objects: for any o1 and o2, o1.equals(o2) implies
Arrays.equals(serialize(o1), serialize(o2)).
serialize in interface Serializer<T>item - the object to serialize.public static <T> Serializer<T> create(Function<T,String> toString)
toString - the function to convert items to string as an intermediate representation.public static Serializer<String> create()
Copyright © 2014. All rights reserved.