public class JacksonParserHandle extends com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser> implements OutputStreamSender, StreamingContentHandle<com.fasterxml.jackson.core.JsonParser,java.io.InputStream>, JSONReadHandle, JSONWriteHandle, StructureReadHandle, StructureWriteHandle, CtsQueryWriteHandle, java.io.Closeable
An adapter for using the streaming capabilities of the Jackson Open Source library. Enables low-level efficient reading and writing of JSON documents.
Always call close()
when finished with this handle to release the resources.
UNKNOWN_LENGTH
Constructor and Description |
---|
JacksonParserHandle() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Always call close() when finished with this handle -- it closes the underlying InputStream.
|
com.fasterxml.jackson.core.JsonParser |
get()
JsonParser allows streaming access to content as it arrives.
|
java.lang.Class<com.fasterxml.jackson.core.JsonParser> |
getContentClass()
Returns the class of the handled content, which may be a base
class of the actual class of a content object.
|
com.fasterxml.jackson.databind.ObjectMapper |
getMapper()
Provides access to the ObjectMapper used internally so you can configure
it to fit your JSON.
|
protected boolean |
hasContent() |
com.fasterxml.jackson.core.JsonParser[] |
newArray(int length)
Constructs an array for the handled content representation
|
static ContentHandleFactory |
newFactory()
Creates a factory to create a JacksonParserHandle instance for a JsonParser.
|
JacksonParserHandle |
newHandle()
Constructs a new handle for the same content representation,
initializing the new handle with the same format and mime type.
|
JacksonParserHandle[] |
newHandleArray(int length)
Constructs an uninitialized array with the specified length with items
of the same content representation.
|
protected void |
receiveContent(java.io.InputStream content) |
protected OutputStreamSender |
sendContent() |
protected OutputStreamSender |
sendContent(com.fasterxml.jackson.core.JsonParser parser) |
void |
set(com.fasterxml.jackson.core.JsonParser parser)
Available for the edge case that content from a JsonParser must be written.
|
void |
setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
Enables clients to specify their own ObjectMapper instance, including databinding mappers
for formats other than JSON.
|
com.fasterxml.jackson.core.JsonParser |
toContent(java.io.InputStream serialization)
Converts the serialization to the content representation.
|
JacksonParserHandle |
with(com.fasterxml.jackson.core.JsonParser parser)
Assigns the JsonParser and returns the handle.
|
JacksonParserHandle |
withFormat(Format format)
Specifies the format of the content and returns the handle
as a fluent convenience.
|
JacksonParserHandle |
withMimetype(java.lang.String mimetype)
Specifies the mime type of the content and returns the handle
as a fluent convenience.
|
void |
write(java.io.OutputStream out)
Implements a callback to write content to the provided output stream
for sending to the database server.
|
bytesToContent, contentToBytes, fromBuffer, receiveAs, toBuffer, toString
getByteLength, getFormat, getMimetype, getServerTimestamp, setByteLength, setFormat, setMimetype, setServerTimestamp
getPointInTimeQueryTimestamp, isResendable, setPointInTimeQueryTimestamp, setResendable, setResponseServerTimestamp
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
resendableHandleFor
bytesToContent, contentToBytes, newHandle, resendableHandleFor
fromBuffer, toBuffer
public static ContentHandleFactory newFactory()
public JacksonParserHandle withFormat(Format format)
format
- the format of the contentpublic JacksonParserHandle withMimetype(java.lang.String mimetype)
mimetype
- the mime type of the contentpublic com.fasterxml.jackson.core.JsonParser get()
get
in interface ContentHandle<com.fasterxml.jackson.core.JsonParser>
get
in class com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser>
public void set(com.fasterxml.jackson.core.JsonParser parser)
set
in interface ContentHandle<com.fasterxml.jackson.core.JsonParser>
set
in class com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser>
parser
- the JsonParser over the content to be writtenpublic JacksonParserHandle with(com.fasterxml.jackson.core.JsonParser parser)
parser
- the JsonParser over the content to be writtenpublic java.lang.Class<com.fasterxml.jackson.core.JsonParser> getContentClass()
ContentHandle
getContentClass
in interface ContentHandle<com.fasterxml.jackson.core.JsonParser>
public JacksonParserHandle newHandle()
ContentHandle
newHandle
in interface BufferableContentHandle<com.fasterxml.jackson.core.JsonParser,java.io.InputStream>
newHandle
in interface ContentHandle<com.fasterxml.jackson.core.JsonParser>
public JacksonParserHandle[] newHandleArray(int length)
BufferableContentHandle
newHandleArray
in interface BufferableContentHandle<com.fasterxml.jackson.core.JsonParser,java.io.InputStream>
length
- the number of positions in the arraypublic com.fasterxml.jackson.core.JsonParser[] newArray(int length)
ContentHandle
newArray
in interface ContentHandle<com.fasterxml.jackson.core.JsonParser>
length
- the size of the array (zero or more)public com.fasterxml.jackson.databind.ObjectMapper getMapper()
getMapper
in class com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser>
public void setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
ObjectMapper mapper = new CsvMapper();
mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
handle.setMapper(mapper);
Use at your own risk! Note that you most likely want to set to false the two options we
demonstrate above (JsonGenerator.Feature.AUTO_CLOSE_TARGET and JsonParser.Feature.AUTO_CLOSE_SOURCE)
as we do so your mapper will not close streams which we may need to reuse if we have to
resend a network request.setMapper
in class com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser>
protected OutputStreamSender sendContent()
sendContent
in class com.marklogic.client.impl.HandleImplementation<java.io.InputStream,OutputStreamSender>
protected OutputStreamSender sendContent(com.fasterxml.jackson.core.JsonParser parser)
sendContent
in class com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser>
protected void receiveContent(java.io.InputStream content)
receiveContent
in class com.marklogic.client.impl.HandleImplementation<java.io.InputStream,OutputStreamSender>
protected boolean hasContent()
hasContent
in class com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser>
public void write(java.io.OutputStream out) throws java.io.IOException
OutputStreamSender
write
in interface OutputStreamSender
out
- the output stream receiving the contentjava.io.IOException
- if io problems arisepublic com.fasterxml.jackson.core.JsonParser toContent(java.io.InputStream serialization)
BufferableContentHandle
toContent
in interface BufferableContentHandle<com.fasterxml.jackson.core.JsonParser,java.io.InputStream>
toContent
in class com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser>
serialization
- a serialization of the contentpublic void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
Copyright © 2013-2021 MarkLogic Corporation.