public class AsJsons<InputT>
extends org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<InputT>,org.apache.beam.sdk.values.PCollection<java.lang.String>>
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.| Modifier and Type | Class and Description |
|---|---|
class |
AsJsons.AsJsonsWithFailures<FailureT>
A
PTransform that adds exception handling to AsJsons. |
| Modifier and Type | Method and Description |
|---|---|
<NewFailureT> |
exceptionsInto(org.apache.beam.sdk.values.TypeDescriptor<NewFailureT> failureTypeDescriptor)
Returns a new
AsJsons.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 using AsJsons.AsJsonsWithFailures.exceptionsVia(ProcessFunction). |
AsJsons.AsJsonsWithFailures<org.apache.beam.sdk.values.KV<InputT,java.util.Map<java.lang.String,java.lang.String>>> |
exceptionsVia()
Returns a new
AsJsons.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 handler DefaultExceptionAsMapHandler and
emitting the result to a failure collection. |
<FailureT> AsJsons.AsJsonsWithFailures<FailureT> |
exceptionsVia(org.apache.beam.sdk.transforms.InferableFunction<org.apache.beam.sdk.transforms.WithFailures.ExceptionElement<InputT>,FailureT> exceptionHandler)
Returns a new
AsJsons.AsJsonsWithFailures transform that catches exceptions raised while
writing JSON elements, passing the raised exception instance and the input element being
processed through the given exceptionHandler and emitting the result to a failure
collection. |
org.apache.beam.sdk.values.PCollection<java.lang.String> |
expand(org.apache.beam.sdk.values.PCollection<InputT> input) |
static <InputT> AsJsons<InputT> |
of(java.lang.Class<? extends InputT> inputClass)
Creates a
AsJsons PTransform that will transform a PCollection<InputT>
into a PCollection of JSON Strings representing those objects using a
Jackson ObjectMapper. |
AsJsons<InputT> |
withMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
Use custom Jackson
ObjectMapper instead of the default one. |
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setDisplayData, setResourceHints, toString, validate, validatepublic static <InputT> AsJsons<InputT> of(java.lang.Class<? extends InputT> inputClass)
AsJsons PTransform that will transform a PCollection<InputT>
into a PCollection of JSON Strings representing those objects using a
Jackson ObjectMapper.public AsJsons<InputT> withMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
ObjectMapper instead of the default one.public <NewFailureT> AsJsons.AsJsonsWithFailures<NewFailureT> exceptionsInto(org.apache.beam.sdk.values.TypeDescriptor<NewFailureT> failureTypeDescriptor)
AsJsons.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 using AsJsons.AsJsonsWithFailures.exceptionsVia(ProcessFunction).
See WithFailures documentation for usage patterns of the returned WithFailures.Result.
public <FailureT> AsJsons.AsJsonsWithFailures<FailureT> exceptionsVia(org.apache.beam.sdk.transforms.InferableFunction<org.apache.beam.sdk.transforms.WithFailures.ExceptionElement<InputT>,FailureT> exceptionHandler)
AsJsons.AsJsonsWithFailures transform that catches exceptions raised while
writing JSON 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<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();
public AsJsons.AsJsonsWithFailures<org.apache.beam.sdk.values.KV<InputT,java.util.Map<java.lang.String,java.lang.String>>> exceptionsVia()
AsJsons.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 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<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();
public org.apache.beam.sdk.values.PCollection<java.lang.String> expand(org.apache.beam.sdk.values.PCollection<InputT> input)
expand in class org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<InputT>,org.apache.beam.sdk.values.PCollection<java.lang.String>>