public abstract class Json extends Object
JSON values are divided into input and output values. Input values are provided by code that wants to bind values to a query. Input values are intended to be consumed by the driver. Input values should not be consumed by application code.
Output values are returned by the driver to be consumed by application code using the following methods:
JSON values should be generally considered for single-consumption only. Output values retain a reference to a potentially pooled memory buffer and must be consumed to avoid memory leaks.
Modifier and Type | Method and Description |
---|---|
abstract byte[] |
asArray()
Returns the value as
byte[] . |
abstract String |
asString()
Returns the value as
String . |
abstract <T> T |
mapBuffer(Function<ByteBuffer,? extends T> mappingFunction)
Returns an object consisting of the result of applying the given
mapping
Function to the ByteBuffer of this JSON value. |
abstract <T> T |
mapByteBuf(Function<io.netty.buffer.ByteBuf,? extends T> mappingFunction)
Returns an object consisting of the result of applying the given
mapping
Function to the ByteBuf of this JSON value. |
abstract <T> T |
mapInputStream(Function<InputStream,? extends T> mappingFunction)
Returns an object consisting of the result of applying the given
mapping
Function to the InputStream of this JSON value. |
static Json |
of(byte[] value)
Creates a
Json object from a byte[] value . |
static Json |
of(io.netty.buffer.ByteBuf buffer)
Creates a
Json object from a ByteBuf . |
static Json |
of(ByteBuffer buffer)
Creates a
Json object from a ByteBuffer . |
static Json |
of(InputStream inputStream)
Creates a
Json object from a InputStream . |
static Json |
of(String value)
|
public static Json of(ByteBuffer buffer)
Json
object from a ByteBuffer
.buffer
- the JSON value as ByteBuffer
Json
object from a ByteBuffer
.IllegalArgumentException
- if buffer
is null
public static Json of(io.netty.buffer.ByteBuf buffer)
buffer
- the JSON value as ByteBuf
Json
object from a ByteBuf
.IllegalArgumentException
- if buffer
is null
public static Json of(InputStream inputStream)
inputStream
- the JSON value as InputStream
Json
object from a InputStream
.IllegalArgumentException
- if inputStream
is null
public static Json of(byte[] value)
Json
object from a byte[] value
.value
- the JSON value as byte[]
Json
object from a byte[] value
.IllegalArgumentException
- if value
is null
public static Json of(String value)
Json
object from a String
. Uses UTF-8 encoding to convert the value into its binary representation.value
- the JSON value as String
Json
object from a String
.IllegalArgumentException
- if value
is null
@Nullable public abstract <T> T mapBuffer(Function<ByteBuffer,? extends T> mappingFunction)
Function
to the ByteBuffer
of this JSON value.
Consumption methods should be called exactly once as the underlying JSON value is typically released after consumption.
T
- return type.mappingFunction
- mapping function that gets applied to the ByteBuffer
representation of this JSON value.null
.@Nullable public abstract <T> T mapByteBuf(Function<io.netty.buffer.ByteBuf,? extends T> mappingFunction)
Function
to the ByteBuf
of this JSON value.
Consumption methods should be called exactly once as the underlying JSON value is typically released after consumption.
T
- return type.mappingFunction
- mapping function that gets applied to the ByteBuf
representation of this JSON value.null
.@Nullable public abstract <T> T mapInputStream(Function<InputStream,? extends T> mappingFunction)
Function
to the InputStream
of this JSON value.
Consumption methods should be called exactly once as the underlying JSON value is typically released after consumption.
T
- return type.mappingFunction
- mapping function that gets applied to the InputStream
representation of this JSON value.null
.public abstract byte[] asArray()
byte[]
.
Consumption methods should be called exactly once as the underlying JSON value is typically released after consumption.
byte[]
.Copyright © 2019. All rights reserved.