Class JsonUtils
java.lang.Object
org.apache.beam.sdk.schemas.utils.JsonUtils
Utils to convert JSON records to Beam
Row.
JSON-Schema (https://json-schema.org) support
This class provides utility methods to parse, validate and translate between JSON
Schema-formatted schemas and Beam Schemas. The support is based on the
everit-json-schema package, which is not provided by default.
Therefore, functionality in
} requires that you
include invalid @link
{@link JsonUtils::beamSchemaFromJsonSchema
everit-json-schema in your project like so:
<dependency>
<groupId>com.github.erosb < /groupId>
<artifactId>everit-json-schema < /artifactId>
<version>${everit-json.version} < /version>
< /dependency>
Note: This functionality has been tested with everit-json-schema version
1.14.2.
JSON-Schema supported features
The current Beam implementation does not support all possible features of JSON-schema. The current implementation supports:
- String, boolean and numeric values (integer and floating-point).
- Arrays with any one of the supported types as elements. This includes nested arrays.
- Objects with any of the supported types as fields. This includes nested objects.
- Fields marked as required are non-null. Other fields are nullable.
The following JSON-schema features are not supported:
- Tuple-like arrays (or arrays with multiple item types).
- Validation of row regular expressions, enum values, array lengths, etc.
- Special annotations for types (e.g.
contentMediaType) are ignored. - Composite schemas (schemas made out of a combination of other schemas)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SchemabeamSchemaFromJsonSchema(String jsonSchemaStr) static SimpleFunction<byte[], Row> getJsonBytesToRowFunction(Schema beamSchema) Returns aSimpleFunctionmapping JSON byte[] arrays to BeamRows.static SimpleFunction<String, Row> getJsonStringToRowFunction(Schema beamSchema) static SimpleFunction<Row, byte[]> getRowToJsonBytesFunction(Schema beamSchema) Returns aSimpleFunctionmapping BeamRows to JSON byte[] arrays.static SimpleFunction<Row, String> getRowToJsonStringsFunction(Schema beamSchema) static ObjectSchemajsonSchemaFromBeamSchema(Schema beamSchema) static StringjsonSchemaStringFromBeamSchema(Schema beamSchema)
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
getJsonBytesToRowFunction
Returns aSimpleFunctionmapping JSON byte[] arrays to BeamRows. -
getJsonStringToRowFunction
-
getRowToJsonBytesFunction
Returns aSimpleFunctionmapping BeamRows to JSON byte[] arrays. -
getRowToJsonStringsFunction
-
jsonSchemaStringFromBeamSchema
-
jsonSchemaFromBeamSchema
-
beamSchemaFromJsonSchema
-