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.AsJsonsWithFailurestransform 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.AsJsonsWithFailurestransform that catches exceptions raised while writing JSON elements, passing the raised exception instance and the input element being processed through the default exception handlerAsJsons.DefaultExceptionAsMapHandlerand emitting the result to a failure collection.<FailureT> AsJsons<InputT>.AsJsonsWithFailures<FailureT> exceptionsVia(InferableFunction<WithFailures.ExceptionElement<InputT>, FailureT> exceptionHandler) Returns a newAsJsons.AsJsonsWithFailurestransform that catches exceptions raised while writing JSON elements, passing the raised exception instance and the input element being processed through the givenexceptionHandlerand emitting the result to a failure collection.expand(PCollection<InputT> input) Override this method to specify how thisPTransformshould be expanded on the givenInputT.static <InputT> AsJsons<InputT> Creates aAsJsonsPTransformthat will transform aPCollection<InputT>into aPCollectionof JSONStringsrepresenting those objects using a JacksonObjectMapper.withMapper(ObjectMapper mapper) Use custom JacksonObjectMapperinstead 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 aAsJsonsPTransformthat will transform aPCollection<InputT>into aPCollectionof JSONStringsrepresenting those objects using a JacksonObjectMapper. -
withMapper
Use custom JacksonObjectMapperinstead of the default one. -
exceptionsInto
public <NewFailureT> AsJsons<InputT>.AsJsonsWithFailures<NewFailureT> exceptionsInto(TypeDescriptor<NewFailureT> failureTypeDescriptor) Returns a newAsJsons.AsJsonsWithFailurestransform 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
WithFailuresdocumentation for usage patterns of the returnedWithFailures.Result. -
exceptionsVia
public <FailureT> AsJsons<InputT>.AsJsonsWithFailures<FailureT> exceptionsVia(InferableFunction<WithFailures.ExceptionElement<InputT>, FailureT> exceptionHandler) Returns a newAsJsons.AsJsonsWithFailurestransform that catches exceptions raised while writing JSON elements, passing the raised exception instance and the input element being processed through the givenexceptionHandlerand emitting the result to a failure collection.See
WithFailuresdocumentation 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.AsJsonsWithFailurestransform that catches exceptions raised while writing JSON elements, passing the raised exception instance and the input element being processed through the default exception handlerAsJsons.DefaultExceptionAsMapHandlerand emitting the result to a failure collection.See
AsJsons.DefaultExceptionAsMapHandlerfor more details about default handler behavior.See
WithFailuresdocumentation 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:PTransformOverride this method to specify how thisPTransformshould be expanded on the givenInputT.NOTE: This method should not be called directly. Instead apply the
PTransformshould be applied to theInputTusing theapplymethod.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:
expandin classPTransform<PCollection<InputT>,PCollection<String>>
-