{"record":{"id":"5c7130b6c336cac9","repo":"apache/beam","slug":"failed-to-convert-pipelineoptions-to-json","errorCode":null,"errorMessage":"Failed to convert PipelineOptions to JSON","messagePattern":"Failed to convert PipelineOptions to JSON","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/PipelineOptionsTranslation.java","lineNumber":135,"sourceCode":"        // Legacy options.\n        return MAPPER.readValue(optionsJson, PipelineOptions.class);\n      } else {\n        // Fn Options with namespace and version.\n        Struct.Builder builder = Struct.newBuilder();\n        JsonFormat.parser().merge(optionsJson, builder);\n        return fromProto(builder.build());\n      }\n    } catch (IOException e) {\n      throw new RuntimeException(\"Failed to read PipelineOptions from JSON\", e);\n    }\n  }\n\n  /** Converts the provided {@link PipelineOptions} into Json{@link String}. */\n  public static String toJson(PipelineOptions options) {\n    try {\n      return JsonFormat.printer().print(toProto(options));\n    } catch (InvalidProtocolBufferException e) {\n      throw new RuntimeException(\"Failed to convert PipelineOptions to JSON\", e);\n    }\n  }\n}\n","sourceCodeStart":117,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/PipelineOptionsTranslation.java#L117-L139","documentation":"PipelineOptionsTranslation.toJson() serializes a PipelineOptions object to a JSON string by first converting it to a RunnerApi.ProtocolBuffer message and then printing it with JsonFormat.printer(). If the protobuf-to-JSON printing step throws InvalidProtocolBufferException, the method wraps it in a RuntimeException with this message. This indicates the generated proto could not be rendered as JSON, which is normally an internal/invariant failure rather than a user input problem.","triggerScenarios":"Calling PipelineOptionsTranslation.toJson(options) where JsonFormat.printer().print(toProto(options)) throws InvalidProtocolBufferException — e.g. the converted FunctionSpec/proto contains data the JSON printer cannot serialize (malformed Any payloads or fields incompatible with the canonical JSON mapping).","commonSituations":"Building runner pipelines programmatically, submitting jobs to a runner (Flink/Dataflow/Spark) that serializes options, using custom PipelineOptions registrations or custom payload translators that produce unusual proto contents, or Beam version mismatches between SDK and runner producing protos the printer rejects.","solutions":["Inspect the wrapped cause (e.getCause(), the InvalidProtocolBufferException) to identify which field/proto fails JSON conversion.","Simplify or fix the custom PipelineOptions / payload translator producing the offending proto payload.","Verify SDK and runner versions match; upgrade Beam to the latest patch release for the version in use.","As a workaround, serialize options via PipelineOptionsTranslation.toProto(options) directly or rely on the runner's own serialization path."],"exampleFix":"// before\nString json = PipelineOptionsTranslation.toJson(options);\n// after\ntry {\n  String json = PipelineOptionsTranslation.toJson(options);\n} catch (RuntimeException e) {\n  LOG.error(\"Options proto -> JSON failed; proto dump for debug:\", e.getCause());\n  String protoDebug = TextFormat.printer().printToString(PipelineOptionsTranslation.toProto(options));\n}","handlingStrategy":"try-catch","validationCode":"if (options == null) throw new IllegalArgumentException(\"PipelineOptions required\");","typeGuard":null,"tryCatchPattern":"try { String json = PipelineOptionsTranslation.toJson(options); } catch (RuntimeException e) { handleSerializationFailure(e.getCause(), options); }","preventionTips":["Keep SDK and runner versions aligned","Test options serialization in CI before job submission","Inspect the cause chain for the exact proto field that fails"],"tags":["java","beam","serialization","protobuf","pipeline-options"],"backgroundTag":"json-marshal-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}