@Singleton public class JsonMediaTypeCodec extends Object implements MediaTypeCodec
MediaTypeCodec
for JSON and Jackson.Modifier and Type | Field and Description |
---|---|
static String |
CONFIGURATION_QUALIFIER |
Constructor and Description |
---|
JsonMediaTypeCodec(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
ApplicationConfiguration applicationConfiguration,
CodecConfiguration codecConfiguration) |
Modifier and Type | Method and Description |
---|---|
<T> T |
decode(Argument<T> type,
ByteBuffer<?> buffer)
Decode the given type from the given buffer.
|
<T> T |
decode(Argument<T> type,
InputStream inputStream)
Decode the given type from the given
InputStream . |
<T> T |
decode(Argument<T> type,
com.fasterxml.jackson.databind.JsonNode node)
Decodes the given JSON node.
|
<T> T |
decode(Argument<T> type,
String data)
Decode the given type from the given bytes.
|
<T> byte[] |
encode(T object)
Encode the given type returning the object as a byte[].
|
<T> ByteBuffer |
encode(T object,
ByteBufferFactory allocator)
Encode the given type returning the object as a
ByteBuffer . |
<T> void |
encode(T object,
OutputStream outputStream)
Encode the given type to the given
OutputStream . |
Collection<MediaType> |
getMediaTypes() |
com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper() |
boolean |
supportsType(Class<?> type)
Whether the codec can decode the given type.
|
public static final String CONFIGURATION_QUALIFIER
public JsonMediaTypeCodec(com.fasterxml.jackson.databind.ObjectMapper objectMapper, ApplicationConfiguration applicationConfiguration, @Named(value="json") @Nullable CodecConfiguration codecConfiguration)
objectMapper
- To read/write JSONapplicationConfiguration
- The common application configurationscodecConfiguration
- The configuration for the codecpublic com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
public boolean supportsType(Class<?> type)
MediaTypeCodec
supportsType
in interface MediaTypeCodec
type
- The typepublic Collection<MediaType> getMediaTypes()
getMediaTypes
in interface MediaTypeCodec
public <T> T decode(Argument<T> type, InputStream inputStream) throws CodecException
MediaTypeCodec
InputStream
.decode
in interface MediaTypeCodec
T
- The generic typetype
- The typeinputStream
- The input streamCodecException
- When the result cannot be decodedpublic <T> T decode(Argument<T> type, com.fasterxml.jackson.databind.JsonNode node) throws CodecException
T
- The generic typetype
- The typenode
- The Json NodeCodecException
- When object cannot be decodedpublic <T> T decode(Argument<T> type, ByteBuffer<?> buffer) throws CodecException
MediaTypeCodec
ByteBuffer
instances
should override this method.decode
in interface MediaTypeCodec
T
- The decoded typetype
- The typebuffer
- the bufferCodecException
- When the result cannot be decodedpublic <T> T decode(Argument<T> type, String data) throws CodecException
MediaTypeCodec
decode
in interface MediaTypeCodec
T
- The decoded typetype
- The typedata
- The data as a stringCodecException
- When the result cannot be decodedpublic <T> void encode(T object, OutputStream outputStream) throws CodecException
MediaTypeCodec
OutputStream
.encode
in interface MediaTypeCodec
T
- The generic typeobject
- The object to encodeoutputStream
- The output streamCodecException
- When the result cannot be encodedpublic <T> byte[] encode(T object) throws CodecException
MediaTypeCodec
encode
in interface MediaTypeCodec
T
- The generic typeobject
- The object to encodeCodecException
- When the result cannot be encodedpublic <T> ByteBuffer encode(T object, ByteBufferFactory allocator) throws CodecException
MediaTypeCodec
ByteBuffer
.encode
in interface MediaTypeCodec
T
- The generic typeobject
- The object to encodeallocator
- The allocatorCodecException
- When the result cannot be encoded