Interface JacksonProvider
- All Superinterfaces:
NamedObjectProcessor.Provider,ObjectProcessor.Provider
JSON value processor implementation using
Jackson>.
This implementation allows users to efficiently parse / destructure a
JSON value (from a supported input type) into writable chunks according to the type(s) as specified by its Value type. This is done using the Jackson streaming
API JsonParser (as opposed to the databind / object mapping API, which must first create intermediate
objects).
The "simple" types are self-explanatory. For example, the StringValue represents a String output
type, and (by default) expects a JSON string as input; the IntValue represents an int output type,
and (by default) expects a JSON number as input. The allowed JSON input types can be specified via
allowed types; users are encouraged to use the strictest type they can according to how
their JSON data is serialized.
The most common "complex" type is ObjectValue, which expects to parse a JSON object of known fields. The
object contains ObjectValue.fields(), which represent other values. The fields are recursively
resolved and flattened into the ObjectProcessor.outputTypes(). For example, a JSON object, which itself
contains another JSON object
{
"city": "Plymouth",
"point": {
"latitude": 45.018269,
"longitude": -93.473892
}
}
when represented with structuring as one might expect (ObjectValue(StringValue,
ObjectValue(DoubleValue, DoubleValue))), will produce output types representing [String, double, double]. Furthermore, the field names and delimiter "_" will be
used by default to provide the names
["city", "point_latitude", "point_longitude"].
The ArrayValue represents a variable-length array, which expects to parse a JSON array where each element is
expected to have the same element type. (This is in contrast to JSON arrays more
generally, where each element of the array can be a different JSON value type.) The output type will be the output
type(s) of the element type as the component type of a native array, Type.arrayType(). For example, if we
used the previous example as the array component type, it will produce
output types representing [String[], double[], double[]] (the
names will remain unchanged).
The TupleValue represents a fixed number of value types, which expects to
parse a fixed-length JSON array where each element corresponds to the same-indexed value type. The values are
recursively resolved and flattened into the ObjectProcessor.outputTypes(); for example, the earlier example's
data could be re-represented as the JSON array
["Plymouth", 45.018269, -93.473892]and structured as one might expect (
TupleValue(StringValue, DoubleValue,
DoubleValue)), and will produce output types representing
[String, double, double]. Even though no field names are present in the JSON value, users may set
names for each element (and will otherwise inherit integer-indexed default names).
The TypedObjectValue represents a union of object values where the first field is
type-discriminating. For example, the following might be modelled as a type-discriminated object with
type-discriminating field "type", shared "symbol" StringValue, "quote" object of "bid" DoubleValue
and an "ask" DoubleValue, and "trade" object containing a "price" DoubleValue and a "size"
LongValue.
{
"type": "quote",
"symbol": "BAR",
"bid": 10.01,
"ask": 10.05
}
{
"type": "trade",
"symbol": "FOO",
"price": 70.03,
"size": 42
}
The output types are first the type-discriminating field, then the shared
fields (if any), followed by the individual object value fields; with the above example, that
would result in output types
[String, String, double, double, double long] and names
["type", "symbol", "quote_bid", "quote_ask", "trade_price", "trade_size"].
The ObjectEntriesValue represents a variable-length object, which expects to parse a JSON object where each
key-value entry has a common value type. The output type will be the key and value
element types as a component of native arrays (Type.arrayType()). For example, a JSON object, whose values
are also JSON objects
{
"Plymouth": {
"latitude": 45.018269,
"longitude": -93.473892
},
"New York": {
"latitude": 40.730610,
"longitude": -73.935242
}
}
when represented with structuring as one might expect (ObjectEntriesValue(StringValue,
ObjectValue(DoubleValue, DoubleValue))), will produce output types representing [String[], double[], double[]], and names
["Key", "latitude", "longitude"].
The AnyValue type represents a TreeNode output; this requires that the Jackson databinding API be
available on the classpath. This is useful for initial modelling and debugging purposes.
-
Method Summary
Modifier and TypeMethodDescriptionCreates aByteBufferjson object processor.ObjectProcessor<byte[]>Creates abyte[]json object processor.Creates aCharBufferjson object processor.ObjectProcessor<char[]>Creates achar[]json object processor.Creates aFilejson object processor.The supported types.The supported types.static JacksonProviderCreates a jackson provider using a default factory.static JacksonProviderCreates a jackson provider using the providedfactory.Creates aPathjson object processor.<T> ObjectProcessor<? super T>Creates an object processor based on theinputTypewith a defaultJsonFactory.Creates aStringjson object processor.Creates aURLjson object processor.Methods inherited from interface io.deephaven.processor.NamedObjectProcessor.Provider
named, namesMethods inherited from interface io.deephaven.processor.ObjectProcessor.Provider
outputSize, outputTypes
-
Method Details
-
of
Creates a jackson provider using a default factory. Equivalent toof(options, JacksonConfiguration.defaultFactoryBuilder().build()).- Parameters:
options- the object options- Returns:
- the jackson provider
- See Also:
-
of
Creates a jackson provider using the providedfactory.- Parameters:
options- the object optionsfactory- the jackson factory- Returns:
- the jackson provider
-
getInputTypes
- Returns:
- the supported types
-
inputTypes
The supported types. Equivalent togetInputTypes().- Specified by:
inputTypesin interfaceObjectProcessor.Provider- Returns:
- the supported types
-
processor
Creates an object processor based on theinputTypewith a defaultJsonFactory.- Specified by:
processorin interfaceObjectProcessor.Provider- Type Parameters:
T- the input type- Parameters:
inputType- the input type- Returns:
- the object processor
- See Also:
-
names
-
stringProcessor
ObjectProcessor<String> stringProcessor()Creates aStringjson object processor.- Returns:
- the object processor
- See Also:
-
JsonFactory.createParser(String)
-
bytesProcessor
ObjectProcessor<byte[]> bytesProcessor()Creates abyte[]json object processor.- Returns:
- the object processor
- See Also:
-
JsonFactory.createParser(byte[])
-
charsProcessor
ObjectProcessor<char[]> charsProcessor()Creates achar[]json object processor.- Returns:
- the object processor
- See Also:
-
JsonFactory.createParser(char[])
-
fileProcessor
ObjectProcessor<File> fileProcessor()Creates aFilejson object processor.- Returns:
- the object processor
- See Also:
-
JsonFactory.createParser(File)
-
pathProcessor
ObjectProcessor<Path> pathProcessor()Creates aPathjson object processor.- Returns:
- the object processor
-
urlProcessor
ObjectProcessor<URL> urlProcessor()Creates aURLjson object processor.- Returns:
- the object processor
- See Also:
-
JsonFactory.createParser(URL)
-
byteBufferProcessor
ObjectProcessor<ByteBuffer> byteBufferProcessor()Creates aByteBufferjson object processor.- Returns:
- the object processor
-
charBufferProcessor
ObjectProcessor<CharBuffer> charBufferProcessor()Creates aCharBufferjson object processor.- Returns:
- the object processor
-