Class JacksonSerializer<T>
- java.lang.Object
-
- io.github.oberhoff.distributedcaffeine.serializer.JacksonSerializer<T>
-
- Type Parameters:
T
- the type of the object to serialize
- All Implemented Interfaces:
JsonSerializer<T>
,Serializer<T,String>
,StringSerializer<T>
public class JacksonSerializer<T> extends Object implements JsonSerializer<T>
Implementation of a serializer with JSON representation (encoded as String or BSON) based on Jackson.- Author:
- Andreas Oberhoff
- See Also:
- Jackson on GitHub
-
-
Constructor Summary
Constructors Constructor Description JacksonSerializer(com.fasterxml.jackson.core.type.TypeReference<T> typeReference, boolean storeAsBson)
Constructs a serializer with JSON representation based on Jackson along withTypeReference
-based type information.JacksonSerializer(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, boolean storeAsBson)
Constructs a serializer with JSON representation based on Jackson along with a customizableObjectMapper
andTypeReference
-based type information.JacksonSerializer(com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<? super T> typeClass, boolean storeAsBson)
Constructs a serializer with JSON representation based on Jackson along with a customizableObjectMapper
andClass
-based type information.JacksonSerializer(Class<? super T> typeClass, boolean storeAsBson)
Constructs a serializer with JSON representation based on Jackson along withClass
-based type information.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
deserialize(String value)
Deserializes a value.String
serialize(T object)
Serializes an object.boolean
storeAsBson()
Indicates whether the JSON representation should be encoded as BSON or as string when stored in the MongoDB collection.
-
-
-
Constructor Detail
-
JacksonSerializer
public JacksonSerializer(Class<? super T> typeClass, boolean storeAsBson)
Constructs a serializer with JSON representation based on Jackson along withClass
-based type information.- Parameters:
typeClass
- theClass
of the object to serializestoreAsBson
-true
for BSON encoding orfalse
for string encoding
-
JacksonSerializer
public JacksonSerializer(com.fasterxml.jackson.core.type.TypeReference<T> typeReference, boolean storeAsBson)
Constructs a serializer with JSON representation based on Jackson along withTypeReference
-based type information.- Parameters:
typeReference
- theTypeReference
of the object to serializestoreAsBson
-true
for BSON encoding orfalse
for string encoding
-
JacksonSerializer
public JacksonSerializer(com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<? super T> typeClass, boolean storeAsBson)
Constructs a serializer with JSON representation based on Jackson along with a customizableObjectMapper
andClass
-based type information.- Parameters:
objectMapper
- the customizedObjectMapper
typeClass
- theClass
of the object to serializestoreAsBson
-true
for BSON encoding orfalse
for string encoding
-
JacksonSerializer
public JacksonSerializer(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, boolean storeAsBson)
Constructs a serializer with JSON representation based on Jackson along with a customizableObjectMapper
andTypeReference
-based type information.- Parameters:
objectMapper
- the customizedObjectMapper
typeReference
- theTypeReference
of the object to serializestoreAsBson
-true
for BSON encoding orfalse
for string encoding
-
-
Method Detail
-
serialize
public String serialize(T object) throws SerializerException
Description copied from interface:Serializer
Serializes an object.- Specified by:
serialize
in interfaceSerializer<T,String>
- Specified by:
serialize
in interfaceStringSerializer<T>
- Parameters:
object
- the object to be serialized- Returns:
- the serialized value
- Throws:
SerializerException
- if serialization fails
-
deserialize
public T deserialize(String value) throws SerializerException
Description copied from interface:Serializer
Deserializes a value.- Specified by:
deserialize
in interfaceSerializer<T,String>
- Specified by:
deserialize
in interfaceStringSerializer<T>
- Parameters:
value
- the value to be deserialized- Returns:
- the deserialized object
- Throws:
SerializerException
- if deserialization fails
-
storeAsBson
public boolean storeAsBson()
Description copied from interface:JsonSerializer
Indicates whether the JSON representation should be encoded as BSON or as string when stored in the MongoDB collection.- Specified by:
storeAsBson
in interfaceJsonSerializer<T>
- Returns:
true
for BSON encoding orfalse
for string encoding
-
-