{"record":{"id":"c00e88aa776852eb","repo":"apache/beam","slug":"failed-to-parse-a-s-from-json-value-s","errorCode":null,"errorMessage":"Failed to parse a %s from JSON value: %s","messagePattern":"Failed to parse a (.+?) from JSON value: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/jackson/src/main/java/org/apache/beam/sdk/extensions/jackson/ParseJsons.java","lineNumber":157,"sourceCode":"        exceptionHandler, exceptionHandler.getOutputTypeDescriptor());\n  }\n\n  private OutputT readValue(String input) throws IOException {\n    ObjectMapper mapper = Optional.ofNullable(customMapper).orElse(DEFAULT_MAPPER);\n    return mapper.readValue(input, outputClass);\n  }\n\n  @Override\n  public PCollection<OutputT> expand(PCollection<String> input) {\n    return input.apply(\n        MapElements.via(\n            new SimpleFunction<String, OutputT>() {\n              @Override\n              public OutputT apply(String input) {\n                try {\n                  return readValue(input);\n                } catch (IOException e) {\n                  throw new RuntimeException(\n                      \"Failed to parse a \" + outputClass.getName() + \" from JSON value: \" + input,\n                      e);\n                }\n              }\n            }));\n  }\n\n  /** A {@code PTransform} that adds exception handling to {@link ParseJsons}. */\n  public class ParseJsonsWithFailures<FailureT>\n      extends PTransform<PCollection<String>, WithFailures.Result<PCollection<OutputT>, FailureT>> {\n\n    private @Nullable InferableFunction<WithFailures.ExceptionElement<String>, FailureT>\n        exceptionHandler;\n\n    private final transient @Nullable TypeDescriptor<FailureT> failureType;\n\n    ParseJsonsWithFailures(\n        InferableFunction<WithFailures.ExceptionElement<String>, FailureT> exceptionHandler,","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/jackson/src/main/java/org/apache/beam/sdk/extensions/jackson/ParseJsons.java#L139-L175","documentation":"ParseJsons<OutputT> parses JSON strings into OutputT instances using a Jackson ObjectMapper. A readValue failure (malformed JSON, shape mismatch, missing module) throws IOException, which is rethrown as a RuntimeException identifying the target class and the offending JSON string.","triggerScenarios":"Applying ParseJsons.toClass(TypeT) to input strings that are not valid JSON or do not match the target schema (wrong field types, unknown structure), or missing modules for types like Instant.","commonSituations":"Malformed lines in a text/JSON source, wrong Dataflow/POJO class after schema evolution, missing jackson-datatype-jsr310 module for java.time types.","solutions":["Validate/repair upstream JSON (parse each line with try/catch before the transform, or filter invalid records)","Ensure the target class matches the JSON schema (annotations like @JsonIgnoreProperties(ignoreUnknown=true))","Provide a configured ObjectMapper via withObjectMapper, registering required modules"],"exampleFix":"// before\nParseJsons.toClass(Event.class) // fails on java.time fields\n// after\nObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule())\n    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);\nParseJsons.<Event>withObjectMapper(mapper).apply(jsonLines);","handlingStrategy":"try-catch","validationCode":"try { mapper.readValue(sampleJson, Target.class); } catch (IOException e) { /* reject or repair input before the pipeline */ }","typeGuard":null,"tryCatchPattern":"try { parsed = ParseJsons.toClass(Event.class).apply(jsonLines); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Failed to parse a\")) { /* validate JSON or align schema, re-run */ } else throw e; }","preventionTips":["Validate input JSON lines at ingest (schema check, drop dead-letter invalid records)","Keep the target class in sync with the JSON schema (ignore unknown properties)","Register required Jackson modules on a shared ObjectMapper"],"tags":["jackson","json","deserialization","java"],"backgroundTag":"json-parse-error","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}