Class JsonToProtoMessage (3.5.1)

public class JsonToProtoMessage implements ToProtoConverter<Object>

Converts JSON data to Protobuf messages given the Protobuf descriptor and BigQuery table schema. The Protobuf descriptor must have all fields lowercased.

Inheritance

Object > JsonToProtoMessage

Implements

com.google.cloud.bigquery.storage.v1.ToProtoConverter<java.lang.Object>

Static Fields

INSTANCE

public static final JsonToProtoMessage INSTANCE
Field Value
Type Description
JsonToProtoMessage

Static Methods

convertJsonToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONObject json)

public static DynamicMessage convertJsonToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONObject json)
Parameters
Name Description
protoSchema Descriptor
tableSchema TableSchema
json org.json.JSONObject
Returns
Type Description
DynamicMessage

convertJsonToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONObject json, boolean ignoreUnknownFields)

public static DynamicMessage convertJsonToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONObject json, boolean ignoreUnknownFields)
Parameters
Name Description
protoSchema Descriptor
tableSchema TableSchema
json org.json.JSONObject
ignoreUnknownFields boolean
Returns
Type Description
DynamicMessage

convertJsonToProtoMessage(Descriptors.Descriptor protoSchema, JSONObject json)

public static DynamicMessage convertJsonToProtoMessage(Descriptors.Descriptor protoSchema, JSONObject json)
Parameters
Name Description
protoSchema Descriptor
json org.json.JSONObject
Returns
Type Description
DynamicMessage

Constructors

JsonToProtoMessage()

public JsonToProtoMessage()

You can use #INSTANCE instead

Methods

convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, Iterable<Object> jsonArray, boolean ignoreUnknownFields)

public List<DynamicMessage> convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, Iterable<Object> jsonArray, boolean ignoreUnknownFields)

Converts Json array to list of Protobuf

Parameters
Name Description
protoSchema Descriptor

the schema of the output Protobuf schems.

tableSchema TableSchema

tha underlying table schema for which Protobuf is being built.

jsonArray Iterable<Object>

the input JSON array converted to Protobuf.

ignoreUnknownFields boolean

flag indicating that the additional fields not present in the output schema should be accepted.

Returns
Type Description
List<DynamicMessage>

Converted message in Protobuf format.

convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, Object json, boolean ignoreUnknownFields)

public DynamicMessage convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, Object json, boolean ignoreUnknownFields)

Converts input message to Protobuf.

WARNING: it's much more efficient to call the other APIs accepting json array if the jsons share the same table schema.

Parameters
Name Description
protoSchema Descriptor

the schema of the output Protobuf schems.

tableSchema TableSchema

tha underlying table schema for which Protobuf is being built.

json Object

the input JSON object converted to Protobuf.

ignoreUnknownFields boolean

flag indicating that the additional fields not present in the output schema should be accepted.

Returns
Type Description
DynamicMessage

Converted message in Protobuf format.

convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONArray jsonArray, boolean ignoreUnknownFields)

public List<DynamicMessage> convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONArray jsonArray, boolean ignoreUnknownFields)

Converts Json array to list of protocol buffer messages given the protocol buffer descriptor.

Parameters
Name Description
protoSchema Descriptor
tableSchema TableSchema

bigquery table schema is needed for type conversion of DATETIME, TIME, NUMERIC, BIGNUMERIC

jsonArray org.json.JSONArray
ignoreUnknownFields boolean

allows unknown fields in JSON input to be ignored.

Returns
Type Description
List<DynamicMessage>
Exceptions
Type Description
IllegalArgumentException

when JSON data is not compatible with proto descriptor.

convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONObject json)

public DynamicMessage convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONObject json)

Converts Json data to protocol buffer messages given the protocol buffer descriptor.

WARNING: it's much more efficient to call the other APIs accepting json array if the jsons share the same table schema.

Parameters
Name Description
protoSchema Descriptor
tableSchema TableSchema

bigquery table schema is needed for type conversion of DATETIME, TIME, NUMERIC, BIGNUMERIC

json org.json.JSONObject
Returns
Type Description
DynamicMessage
Exceptions
Type Description
IllegalArgumentException

when JSON data is not compatible with proto descriptor.

convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONObject json, boolean ignoreUnknownFields)

public DynamicMessage convertToProtoMessage(Descriptors.Descriptor protoSchema, TableSchema tableSchema, JSONObject json, boolean ignoreUnknownFields)

Converts Json data to protocol buffer messages given the protocol buffer descriptor.

WARNING: it's much more efficient to call the other APIs accepting json array if the jsons share the same table schema.

Parameters
Name Description
protoSchema Descriptor
tableSchema TableSchema

bigquery table schema is needed for type conversion of DATETIME, TIME, NUMERIC, BIGNUMERIC

json org.json.JSONObject
ignoreUnknownFields boolean

allows unknown fields in JSON input to be ignored.

Returns
Type Description
DynamicMessage
Exceptions
Type Description
IllegalArgumentException

when JSON data is not compatible with proto descriptor.

convertToProtoMessage(Descriptors.Descriptor protoSchema, JSONObject json)

public DynamicMessage convertToProtoMessage(Descriptors.Descriptor protoSchema, JSONObject json)

Converts Json data to protocol buffer messages given the protocol buffer descriptor.

WARNING: it's much more efficient to call the other APIs accepting json array if the jsons share the same table schema.

Parameters
Name Description
protoSchema Descriptor
json org.json.JSONObject
Returns
Type Description
DynamicMessage
Exceptions
Type Description
IllegalArgumentException

when JSON data is not compatible with proto descriptor.