Class AsJsons<InputT>
- All Implemented Interfaces:
Serializable
,HasDisplayData
PTransform
for serializing objects to JSON Strings
. Transforms a
PCollection<InputT>
into a PCollection
of JSON Strings
representing
objects in the original PCollection
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>
AsJsons<InputT>.AsJsonsWithFailures<NewFailureT> exceptionsInto
(TypeDescriptor<NewFailureT> failureTypeDescriptor) Returns a newAsJsons.AsJsonsWithFailures
transform that catches exceptions raised while writing JSON elements, with the given type descriptor used for the failure collection but the exception handler yet to be specified usingAsJsons.AsJsonsWithFailures.exceptionsVia(ProcessFunction)
.Returns a newAsJsons.AsJsonsWithFailures
transform that catches exceptions raised while writing JSON elements, passing the raised exception instance and the input element being processed through the default exception handlerAsJsons.DefaultExceptionAsMapHandler
and emitting the result to a failure collection.<FailureT> AsJsons<InputT>.AsJsonsWithFailures
<FailureT> exceptionsVia
(InferableFunction<WithFailures.ExceptionElement<InputT>, FailureT> exceptionHandler) Returns a newAsJsons.AsJsonsWithFailures
transform that catches exceptions raised while writing JSON 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<InputT> input) Override this method to specify how thisPTransform
should be expanded on the givenInputT
.static <InputT> AsJsons
<InputT> Creates aAsJsons
PTransform
that will transform aPCollection<InputT>
into aPCollection
of JSONStrings
representing those objects 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 aAsJsons
PTransform
that will transform aPCollection<InputT>
into aPCollection
of JSONStrings
representing those objects using a JacksonObjectMapper
. -
withMapper
Use custom JacksonObjectMapper
instead of the default one. -
exceptionsInto
public <NewFailureT> AsJsons<InputT>.AsJsonsWithFailures<NewFailureT> exceptionsInto(TypeDescriptor<NewFailureT> failureTypeDescriptor) Returns a newAsJsons.AsJsonsWithFailures
transform that catches exceptions raised while writing JSON elements, with the given type descriptor used for the failure collection but the exception handler yet to be specified usingAsJsons.AsJsonsWithFailures.exceptionsVia(ProcessFunction)
.See
WithFailures
documentation for usage patterns of the returnedWithFailures.Result
. -
exceptionsVia
public <FailureT> AsJsons<InputT>.AsJsonsWithFailures<FailureT> exceptionsVia(InferableFunction<WithFailures.ExceptionElement<InputT>, FailureT> exceptionHandler) Returns a newAsJsons.AsJsonsWithFailures
transform that catches exceptions raised while writing JSON 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<String>, KV<MyPojo, Map<String, String>>> result = pojos.apply( AsJsons.of(MyPojo.class) .exceptionsVia(new WithFailures.ExceptionAsMapHandler<MyPojo>() {})); PCollection<String> output = result.output(); // valid json elements PCollection<KV<MyPojo, Map<String, String>>> failures = result.failures();
-
exceptionsVia
Returns a newAsJsons.AsJsonsWithFailures
transform that catches exceptions raised while writing JSON elements, passing the raised exception instance and the input element being processed through the default exception handlerAsJsons.DefaultExceptionAsMapHandler
and emitting the result to a failure collection.See
AsJsons.DefaultExceptionAsMapHandler
for more details about default handler behavior.See
WithFailures
documentation for usage patterns of the returnedWithFailures.Result
.Example usage:
WithFailures.Result<PCollection<String>, KV<MyPojo, Map<String, String>>> result = pojos.apply( AsJsons.of(MyPojo.class) .exceptionsVia()); PCollection<String> output = result.output(); // valid json elements PCollection<KV<MyPojo, 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<InputT>,
PCollection<String>>
-