Class ParseJsons<OutputT>
- All Implemented Interfaces:
Serializable
,HasDisplayData
PTransform
for parsing JSON Strings
. Parse PCollection
of Strings
in JSON format into a PCollection
of objects represented by those JSON
Strings
using Jackson.- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints
-
Method Summary
Modifier and TypeMethodDescription<NewFailureT>
ParseJsons<OutputT>.ParseJsonsWithFailures<NewFailureT> exceptionsInto
(TypeDescriptor<NewFailureT> failureTypeDescriptor) Returns a newParseJsons.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 usingParseJsons.ParseJsonsWithFailures.exceptionsVia(ProcessFunction)
.Returns a newParseJsons.ParseJsonsWithFailures
transform that catches exceptions raised while parsing elements, passing the raised exception instance and the input element being processed through the default exception handlerParseJsons.DefaultExceptionAsMapHandler
and emitting the result to a failure collection.<FailureT> ParseJsons<OutputT>.ParseJsonsWithFailures
<FailureT> exceptionsVia
(InferableFunction<WithFailures.ExceptionElement<String>, FailureT> exceptionHandler) Returns a newParseJsons.ParseJsonsWithFailures
transform that catches exceptions raised while parsing elements, passing the raised exception instance and the input element being processed through the givenexceptionHandler
and emitting the result to a failure collection.expand
(PCollection<String> input) Override this method to specify how thisPTransform
should be expanded on the givenInputT
.static <OutputT> ParseJsons
<OutputT> Creates aParseJsons
PTransform
that will parse JSONStrings
into aPCollection<OutputT>
using a JacksonObjectMapper
.withMapper
(ObjectMapper mapper) Use custom JacksonObjectMapper
instead of the default one.Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setDisplayData, setResourceHints, toString, validate, validate
-
Method Details
-
of
Creates aParseJsons
PTransform
that will parse JSONStrings
into aPCollection<OutputT>
using a JacksonObjectMapper
. -
withMapper
Use custom JacksonObjectMapper
instead of the default one. -
exceptionsInto
public <NewFailureT> ParseJsons<OutputT>.ParseJsonsWithFailures<NewFailureT> exceptionsInto(TypeDescriptor<NewFailureT> failureTypeDescriptor) Returns a newParseJsons.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 usingParseJsons.ParseJsonsWithFailures.exceptionsVia(ProcessFunction)
.See
WithFailures
documentation for usage patterns of the returnedWithFailures.Result
. -
exceptionsVia
public <FailureT> ParseJsons<OutputT>.ParseJsonsWithFailures<FailureT> exceptionsVia(InferableFunction<WithFailures.ExceptionElement<String>, FailureT> exceptionHandler) Returns a newParseJsons.ParseJsonsWithFailures
transform that catches exceptions raised while parsing elements, passing the raised exception instance and the input element being processed through the givenexceptionHandler
and emitting the result to a failure collection.See
WithFailures
documentation for usage patterns of the returnedWithFailures.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();
-
exceptionsVia
Returns a newParseJsons.ParseJsonsWithFailures
transform that catches exceptions raised while parsing elements, passing the raised exception instance and the input element being processed through the default exception handlerParseJsons.DefaultExceptionAsMapHandler
and emitting the result to a failure collection.See
ParseJsons.DefaultExceptionAsMapHandler
for more details about default handler behavior.See
WithFailures
documentation for usage patterns of the returnedWithFailures.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();
-
expand
Description copied from class:PTransform
Override this method to specify how thisPTransform
should be expanded on the givenInputT
.NOTE: This method should not be called directly. Instead apply the
PTransform
should be applied to theInputT
using theapply
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).
- Specified by:
expand
in classPTransform<PCollection<String>,
PCollection<OutputT>>
-