@InterfaceStability.Uncommitted @InterfaceAudience.Private public class JacksonFragmentTranscoder extends AbstractByteArrayFragmentTranscoder
FragmentTranscoder, based on AbstractByteArrayFragmentTranscoder.
This implementation changes the decodeWithMessage behavior
compared to the parent strategy by attempting to deserialize JSON arrays into JsonArray and JSON
dictionaries into JsonObject.
Care should be taken to not use Jackson specific annotations if you want to be able to
easily swap this for another SubdocumentTranscoder implementation at a later time.| Constructor and Description |
|---|
JacksonFragmentTranscoder(com.couchbase.client.deps.com.fasterxml.jackson.databind.ObjectMapper mapper) |
| Modifier and Type | Method and Description |
|---|---|
protected <T> T |
byteArrayToClass(byte[] byteArray,
int offset,
int length,
Class<? extends T> clazz)
Deserializes a byte array into a specific class instance.
|
protected Object |
byteArrayToGenericObject(byte[] byteArray,
int offset,
int length)
Deserializes a byte array into a generic Object.
|
<T> T |
decodeWithMessage(com.couchbase.client.deps.io.netty.buffer.ByteBuf encoded,
Class<? extends T> clazz,
String transcodingErrorMessage)
Decode content in a
ByteBuf **without releasing it**. |
protected <T> byte[] |
writeValueAsBytes(T value)
Serializes a single value object as an array of bytes.
|
protected void |
writeValueIntoStream(OutputStream out,
Object o)
Serializes a single object out of a sequence of multiple values, into the sequence's
OutputStream. |
doEncodeMulti, doEncodeSingledecode, encode, encodeWithMessagepublic JacksonFragmentTranscoder(com.couchbase.client.deps.com.fasterxml.jackson.databind.ObjectMapper mapper)
public <T> T decodeWithMessage(com.couchbase.client.deps.io.netty.buffer.ByteBuf encoded,
Class<? extends T> clazz,
String transcodingErrorMessage)
throws TranscodingException
FragmentTranscoderByteBuf **without releasing it**. Suitable for populating a
DocumentFragment's content.decodeWithMessage in interface FragmentTranscoderdecodeWithMessage in class AbstractByteArrayFragmentTranscoderT - the type of the decoded fragment.encoded - the encoded fragment value (will not be released).clazz - the target class for decoded value. Using Object.class implies a generic decode,
where dictionaries are represented by JsonObject and arrays by JsonArray.transcodingErrorMessage - the error message to be used in the thrown TranscodingException if the
decoding couldn't happen.TranscodingException - if the decoding couldn't happen.protected Object byteArrayToGenericObject(byte[] byteArray, int offset, int length) throws IOException
AbstractByteArrayFragmentTranscoderByteBuf, which will get released from the heap.
If the array represents a non-scalar value, implementations may choose different classes like a
JsonObject or a Map to instantiate it.
This method is called by AbstractByteArrayFragmentTranscoder.decodeWithMessage(ByteBuf, Class, String) when the clazz parameter is
Object.class.byteArrayToGenericObject in class AbstractByteArrayFragmentTranscoderbyteArray - the array of bytes containing the value to deserialize (you'll need to copy it if long term
usage is needed).offset - the offset in the array at which the value starts.length - the number of bytes after the offset that represents the value.IOExceptionprotected <T> T byteArrayToClass(byte[] byteArray,
int offset,
int length,
Class<? extends T> clazz)
throws IOException
AbstractByteArrayFragmentTranscoderByteBuf, which will get released from the heap.
This method is called by AbstractByteArrayFragmentTranscoder.decodeWithMessage(ByteBuf, Class, String) when the clazz parameter isn't
Object.class.byteArrayToClass in class AbstractByteArrayFragmentTranscoderbyteArray - the array of bytes containing the value to deserialize (you'll need to copy it if long term
usage is needed).offset - the offset in the array at which the value starts.length - the number of bytes after the offset that represents the value.clazz - the Class to deserialize to.IOExceptionprotected <T> byte[] writeValueAsBytes(T value)
throws IOException
AbstractByteArrayFragmentTranscoderByteBuf, so
modifications to the array will be visible in the ByteBuf.writeValueAsBytes in class AbstractByteArrayFragmentTranscodervalue - the value object to serialize.IOExceptionprotected void writeValueIntoStream(OutputStream out, Object o) throws IOException
AbstractByteArrayFragmentTranscoderOutputStream.
Implementation should simply write the bytes corresponding to the serialized value object into the stream.writeValueIntoStream in class AbstractByteArrayFragmentTranscoderout - the OutputStream of bytes representing a JSON sequence of serialized values.o - the value among the sequence that is currently serialized.IOExceptionCopyright © 2015 Couchbase, Inc.