@Experimental public class JsonToRow extends java.lang.Object
Creates a PTransform
to convert input JSON objects to Rows
with given Schema
.
Currently supported Schema
field types are:
Schema.TypeName#BYTE
Schema.TypeName#INT16
Schema.TypeName#INT32
Schema.TypeName#INT64
Schema.TypeName#FLOAT
Schema.TypeName#DOUBLE
Schema.TypeName#BOOLEAN
Schema.TypeName#STRING
For specifics of JSON deserialization see RowJsonDeserializer
.
Conversion is strict, with minimal type coercion:
Booleans are only parsed from true
or false
literals, not from "true"
or "false"
strings or any other values (exception is thrown in these cases).
If a JSON number doesn't fit into the corresponding schema field type, an exception is be thrown. Strings are not auto-converted to numbers. Floating point numbers are not auto-converted to integral numbers. Precision loss also causes exceptions.
Only JSON string values can be parsed into Schema.TypeName.STRING
. Numbers, booleans are not
automatically converted, exceptions are thrown in these cases.
If a schema field is missing from the JSON value, an exception will be thrown.
Explicit null
literals are allowed in JSON objects. No other values are parsed into
null
.
Constructor and Description |
---|
JsonToRow() |
Modifier and Type | Method and Description |
---|---|
static PTransform<PCollection<? extends java.lang.String>,PCollection<Row>> |
withSchema(Schema rowSchema) |
public static PTransform<PCollection<? extends java.lang.String>,PCollection<Row>> withSchema(Schema rowSchema)