Package io.micronaut.jackson.serialize
Class JacksonObjectSerializer
java.lang.Object
io.micronaut.jackson.serialize.JacksonObjectSerializer
- All Implemented Interfaces:
ObjectSerializer
@Singleton
@Bean(typed=JacksonObjectSerializer.class)
public class JacksonObjectSerializer
extends Object
implements ObjectSerializer
An implementation of the
ObjectSerializer
interface for Jackson.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Fields inherited from interface io.micronaut.core.serialize.ObjectSerializer
JDK
-
Constructor Summary
ConstructorDescriptionJacksonObjectSerializer
(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
Method Summary
Modifier and TypeMethodDescription<T> Optional<T>
deserialize
(byte[] bytes, Argument<T> requiredType) Deserialize the given object to bytes.<T> Optional<T>
deserialize
(byte[] bytes, Class<T> requiredType) Deserialize the given object to bytes.<T> Optional<T>
deserialize
(InputStream inputStream, Argument<T> requiredType) Deserialize the given object to bytes.<T> Optional<T>
deserialize
(InputStream inputStream, Class<T> requiredType) Deserialize the given object to bytes.Optional<byte[]>
Serialize the given object to a byte[].void
serialize
(Object object, OutputStream outputStream) Serialize the given object to a byte[].Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.core.serialize.ObjectSerializer
deserialize
-
Constructor Details
-
JacksonObjectSerializer
public JacksonObjectSerializer(com.fasterxml.jackson.databind.ObjectMapper objectMapper) - Parameters:
objectMapper
- To read/write JSON
-
-
Method Details
-
serialize
Description copied from interface:ObjectSerializer
Serialize the given object to a byte[].- Specified by:
serialize
in interfaceObjectSerializer
- Parameters:
object
- The object to serialize- Returns:
- An optional of the bytes of the object
- Throws:
SerializationException
- if there is a serialization problem
-
serialize
Description copied from interface:ObjectSerializer
Serialize the given object to a byte[].- Specified by:
serialize
in interfaceObjectSerializer
- Parameters:
object
- The object to serializeoutputStream
- The output stream- Throws:
SerializationException
- if there is a serialization problem
-
deserialize
public <T> Optional<T> deserialize(byte[] bytes, Class<T> requiredType) throws SerializationException Description copied from interface:ObjectSerializer
Deserialize the given object to bytes.- Specified by:
deserialize
in interfaceObjectSerializer
- Type Parameters:
T
- The required generic type- Parameters:
bytes
- The byte arrayrequiredType
- The required type- Returns:
- An
Optional
of the object - Throws:
SerializationException
- if there is a serialization problem
-
deserialize
public <T> Optional<T> deserialize(InputStream inputStream, Class<T> requiredType) throws SerializationException Description copied from interface:ObjectSerializer
Deserialize the given object to bytes.- Specified by:
deserialize
in interfaceObjectSerializer
- Type Parameters:
T
- The required generic type- Parameters:
inputStream
- The input streamrequiredType
- The required type- Returns:
- An
Optional
of the object - Throws:
SerializationException
- if there is a serialization problem
-
deserialize
public <T> Optional<T> deserialize(byte[] bytes, Argument<T> requiredType) throws SerializationException Description copied from interface:ObjectSerializer
Deserialize the given object to bytes.- Specified by:
deserialize
in interfaceObjectSerializer
- Type Parameters:
T
- The required generic type- Parameters:
bytes
- The byte arrayrequiredType
- The required type- Returns:
- An
Optional
of the object - Throws:
SerializationException
- if there is a serialization problem
-
deserialize
public <T> Optional<T> deserialize(InputStream inputStream, Argument<T> requiredType) throws SerializationException Description copied from interface:ObjectSerializer
Deserialize the given object to bytes.- Specified by:
deserialize
in interfaceObjectSerializer
- Type Parameters:
T
- The required generic type- Parameters:
inputStream
- The input streamrequiredType
- The required type- Returns:
- An
Optional
of the object - Throws:
SerializationException
- if there is a serialization problem
-