public class ParseJsons<OutputT> extends PTransform<PCollection<java.lang.String>,PCollection<OutputT>>
PTransform
for parsing JSON Strings
. Parse PCollection
of Strings
in JSON format into a PCollection
of objects represented by those JSON
Strings
using Jackson.Modifier and Type | Class and Description |
---|---|
class |
ParseJsons.ParseJsonsWithFailures<FailureT>
A
PTransform that adds exception handling to ParseJsons . |
name
Modifier and Type | Method and Description |
---|---|
<NewFailureT> |
exceptionsInto(TypeDescriptor<NewFailureT> failureTypeDescriptor)
Returns a new
ParseJsons.ParseJsonsWithFailures transform that catches exceptions raised while
parsing elements, with the given type descriptor used for the failure collection but the
exception handler yet to be specified using ParseJsons.ParseJsonsWithFailures.exceptionsVia(ProcessFunction) . |
ParseJsons.ParseJsonsWithFailures<KV<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>> |
exceptionsVia()
Returns a new
ParseJsons.ParseJsonsWithFailures transform that catches exceptions raised while
parsing elements, passing the raised exception instance and the input element being processed
through the default exception handler DefaultExceptionAsMapHandler and emitting the
result to a failure collection. |
<FailureT> ParseJsons.ParseJsonsWithFailures<FailureT> |
exceptionsVia(InferableFunction<WithFailures.ExceptionElement<java.lang.String>,FailureT> exceptionHandler)
Returns a new
ParseJsons.ParseJsonsWithFailures transform that catches exceptions raised while
parsing elements, passing the raised exception instance and the input element being processed
through the given exceptionHandler and emitting the result to a failure collection. |
PCollection<OutputT> |
expand(PCollection<java.lang.String> input)
Override this method to specify how this
PTransform should be expanded on the given
InputT . |
static <OutputT> ParseJsons<OutputT> |
of(java.lang.Class<? extends OutputT> outputClass)
Creates a
ParseJsons PTransform that will parse JSON Strings
into a PCollection<OutputT> using a Jackson ObjectMapper . |
ParseJsons<OutputT> |
withMapper(ObjectMapper mapper)
Use custom Jackson
ObjectMapper instead of the default one. |
compose, compose, getAdditionalInputs, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, populateDisplayData, toString, validate
public static <OutputT> ParseJsons<OutputT> of(java.lang.Class<? extends OutputT> outputClass)
ParseJsons
PTransform
that will parse JSON Strings
into a PCollection<OutputT>
using a Jackson ObjectMapper
.public ParseJsons<OutputT> withMapper(ObjectMapper mapper)
ObjectMapper
instead of the default one.@Experimental(value=WITH_EXCEPTIONS) public <NewFailureT> ParseJsons.ParseJsonsWithFailures<NewFailureT> exceptionsInto(TypeDescriptor<NewFailureT> failureTypeDescriptor)
ParseJsons.ParseJsonsWithFailures
transform that catches exceptions raised while
parsing elements, with the given type descriptor used for the failure collection but the
exception handler yet to be specified using ParseJsons.ParseJsonsWithFailures.exceptionsVia(ProcessFunction)
.
See WithFailures
documentation for usage patterns of the returned WithFailures.Result
.
@Experimental(value=WITH_EXCEPTIONS) public <FailureT> ParseJsons.ParseJsonsWithFailures<FailureT> exceptionsVia(InferableFunction<WithFailures.ExceptionElement<java.lang.String>,FailureT> exceptionHandler)
ParseJsons.ParseJsonsWithFailures
transform that catches exceptions raised while
parsing elements, passing the raised exception instance and the input element being processed
through the given exceptionHandler
and emitting the result to a failure collection.
See WithFailures
documentation for usage patterns of the returned WithFailures.Result
.
Example usage:
WithFailures.Result<PCollection<MyPojo>, KV<String, Map<String, String>>> result =
json.apply(
ParseJsons.of(MyPojo.class)
.exceptionsVia(new WithFailures.ExceptionAsMapHandler<String>() {}));
PCollection<MyPojo> output = result.output(); // valid POJOs
PCollection<KV<String, Map<String, String>>> failures = result.failures();
@Experimental(value=WITH_EXCEPTIONS) public ParseJsons.ParseJsonsWithFailures<KV<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>> exceptionsVia()
ParseJsons.ParseJsonsWithFailures
transform that catches exceptions raised while
parsing elements, passing the raised exception instance and the input element being processed
through the default exception handler DefaultExceptionAsMapHandler
and emitting the
result to a failure collection.
See DefaultExceptionAsMapHandler
for more details about default handler behavior.
See WithFailures
documentation for usage patterns of the returned WithFailures.Result
.
Example usage:
WithFailures.Result<PCollection<MyPojo>, KV<String, Map<String, String>>> result =
json.apply(
ParseJsons.of(MyPojo.class)
.exceptionsVia());
PCollection<MyPojo> output = result.output(); // valid POJOs
PCollection<KV<String, Map<String, String>>> failures = result.failures();
public PCollection<OutputT> expand(PCollection<java.lang.String> input)
PTransform
PTransform
should be expanded on the given
InputT
.
NOTE: This method should not be called directly. Instead apply the PTransform
should
be applied to the InputT
using the apply
method.
Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).
expand
in class PTransform<PCollection<java.lang.String>,PCollection<OutputT>>