Class JsonUtils

java.lang.Object
org.apache.beam.sdk.schemas.utils.JsonUtils

public class JsonUtils extends Object
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

invalid @link
{@link JsonUtils::beamSchemaFromJsonSchema
} requires that you include 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)