public class JacksonParserHandle extends com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser> implements ContentHandle<com.fasterxml.jackson.core.JsonParser>, OutputStreamSender, BufferableHandle, JSONReadHandle, JSONWriteHandle, TextReadHandle, TextWriteHandle, XMLReadHandle, XMLWriteHandle, StructureReadHandle, StructureWriteHandle, 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.
|
com.fasterxml.jackson.databind.ObjectMapper |
getMapper()
Provides access to the ObjectMapper used internally so you can configure
it to fit your JSON.
|
static ContentHandleFactory |
newFactory()
Creates a factory to create a JacksonParserHandle instance for a JsonParser.
|
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.
|
JacksonParserHandle |
withFormat(Format format)
Specifies the format of the content and returns the handle
as a fluent convenience.
|
void |
write(OutputStream out)
Implements a callback to write content to the provided output stream
for sending to the database server.
|
fromBuffer, toBuffer, toString
getByteLength, getFormat, getMimetype, setByteLength, setFormat, setMimetype
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
fromBuffer, toBuffer
public static ContentHandleFactory newFactory()
public JacksonParserHandle withFormat(Format format)
format
- the format of the contentpublic com.fasterxml.jackson.core.JsonParser get()
get
in interface ContentHandle<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 contentpublic 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>
public void write(OutputStream out) throws IOException
OutputStreamSender
write
in interface OutputStreamSender
write
in class com.marklogic.client.impl.JacksonBaseHandle<com.fasterxml.jackson.core.JsonParser>
out
- the output stream receiving the contentIOException
- if io problems arisepublic void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2013-2016 MarkLogic Corporation.