Class ParseJsons<OutputT>

java.lang.Object
org.apache.beam.sdk.transforms.PTransform<PCollection<String>,PCollection<OutputT>>
org.apache.beam.sdk.extensions.jackson.ParseJsons<OutputT>
All Implemented Interfaces:
Serializable, HasDisplayData

public class ParseJsons<OutputT> extends PTransform<PCollection<String>,PCollection<OutputT>>
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:
  • Method Details

    • of

      public static <OutputT> ParseJsons<OutputT> of(Class<? extends OutputT> outputClass)
      Creates a ParseJsons PTransform that will parse JSON Strings into a PCollection<OutputT> using a Jackson ObjectMapper.
    • withMapper

      public ParseJsons<OutputT> withMapper(ObjectMapper mapper)
      Use custom Jackson ObjectMapper instead of the default one.
    • exceptionsInto

      public <NewFailureT> ParseJsons<OutputT>.ParseJsonsWithFailures<NewFailureT> exceptionsInto(TypeDescriptor<NewFailureT> failureTypeDescriptor)
      Returns a new ParseJsons.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 using ParseJsons.ParseJsonsWithFailures.exceptionsVia(ProcessFunction).

      See WithFailures documentation for usage patterns of the returned WithFailures.Result.

    • exceptionsVia

      public <FailureT> ParseJsons<OutputT>.ParseJsonsWithFailures<FailureT> exceptionsVia(InferableFunction<WithFailures.ExceptionElement<String>,FailureT> exceptionHandler)
      Returns a new ParseJsons.ParseJsonsWithFailures transform that catches exceptions raised while parsing 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<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 new ParseJsons.ParseJsonsWithFailures transform that catches exceptions raised while parsing elements, passing the raised exception instance and the input element being processed through the default exception handler ParseJsons.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 returned WithFailures.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

      public PCollection<OutputT> expand(PCollection<String> input)
      Description copied from class: PTransform
      Override this method to specify how this PTransform should be expanded on the given InputT.

      NOTE: This method should not be called directly. Instead apply the PTransform should be applied to the InputT using the apply 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 class PTransform<PCollection<String>,PCollection<OutputT>>