Class AsJsons<InputT>
- java.lang.Object
-
- org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<InputT>,org.apache.beam.sdk.values.PCollection<java.lang.String>>
-
- org.apache.beam.sdk.extensions.jackson.AsJsons<InputT>
-
- All Implemented Interfaces:
java.io.Serializable,org.apache.beam.sdk.transforms.display.HasDisplayData
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>>PTransformfor serializing objects to JSONStrings. Transforms aPCollection<InputT>into aPCollectionof JSONStringsrepresenting objects in the originalPCollectionusing Jackson.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAsJsons.AsJsonsWithFailures<FailureT>APTransformthat adds exception handling toAsJsons.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <NewFailureT>
AsJsons.AsJsonsWithFailures<NewFailureT>exceptionsInto(org.apache.beam.sdk.values.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).AsJsons.AsJsonsWithFailures<org.apache.beam.sdk.values.KV<InputT,java.util.Map<java.lang.String,java.lang.String>>>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.<FailureT> AsJsons.AsJsonsWithFailures<FailureT>exceptionsVia(org.apache.beam.sdk.transforms.InferableFunction<org.apache.beam.sdk.transforms.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.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 aAsJsonsPTransformthat will transform aPCollection<InputT>into aPCollectionof JSONStringsrepresenting those objects using a JacksonObjectMapper.AsJsons<InputT>withMapper(com.fasterxml.jackson.databind.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 Detail
-
of
public static <InputT> AsJsons<InputT> of(java.lang.Class<? extends InputT> inputClass)
Creates aAsJsonsPTransformthat will transform aPCollection<InputT>into aPCollectionof JSONStringsrepresenting those objects using a JacksonObjectMapper.
-
withMapper
public AsJsons<InputT> withMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
Use custom JacksonObjectMapperinstead of the default one.
-
exceptionsInto
public <NewFailureT> AsJsons.AsJsonsWithFailures<NewFailureT> exceptionsInto(org.apache.beam.sdk.values.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.AsJsonsWithFailures<FailureT> exceptionsVia(org.apache.beam.sdk.transforms.InferableFunction<org.apache.beam.sdk.transforms.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
public AsJsons.AsJsonsWithFailures<org.apache.beam.sdk.values.KV<InputT,java.util.Map<java.lang.String,java.lang.String>>> 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
public org.apache.beam.sdk.values.PCollection<java.lang.String> expand(org.apache.beam.sdk.values.PCollection<InputT> input)
- Specified by:
expandin classorg.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<InputT>,org.apache.beam.sdk.values.PCollection<java.lang.String>>
-
-