{"record":{"id":"97e6b239b0698246","repo":"apache/iceberg","slug":"failed-to-write-streamingoffset-to-json","errorCode":null,"errorMessage":"Failed to write StreamingOffset to json","messagePattern":"Failed to write StreamingOffset to json","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/StreamingOffset.java","lineNumber":99,"sourceCode":"    }\n\n    return fromJsonNode(node);\n  }\n\n  @Override\n  public String json() {\n    StringWriter writer = new StringWriter();\n    try (JsonGenerator generator = JsonUtil.factory().createGenerator(writer)) {\n      generator.writeStartObject();\n      generator.writeNumberField(VERSION, CURR_VERSION);\n      generator.writeNumberField(SNAPSHOT_ID, snapshotId);\n      generator.writeNumberField(POSITION, position);\n      generator.writeBooleanField(SCAN_ALL_FILES, scanAllFiles);\n      generator.writeEndObject();\n      generator.flush();\n\n    } catch (IOException e) {\n      throw new UncheckedIOException(\"Failed to write StreamingOffset to json\", e);\n    }\n\n    return writer.toString();\n  }\n\n  long snapshotId() {\n    return snapshotId;\n  }\n\n  long position() {\n    return position;\n  }\n\n  boolean shouldScanAllFiles() {\n    return scanAllFiles;\n  }\n\n  @Override","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/StreamingOffset.java#L81-L117","documentation":"StreamingOffset.json() serializes the offset (snapshotId, position, scanAllFiles) to a JSON string using a Jackson generator. Any IOException during generation is wrapped in UncheckedIOException with 'Failed to write StreamingOffset to json' and the cause preserved.","triggerScenarios":"An IOException occurs while writing JSON via the in-memory StringWriter-backed generator — extremely rare since the target is memory, but possible on internal generator failures.","commonSituations":"Rare JVM/Jackson internal failures during offset serialization when Spark persists offsets to the checkpoint directory; usually indicates a JVM resource issue or a Jackson version conflict on the classpath.","solutions":["Check the wrapped cause; it is nearly always a classpath conflict — ensure a single consistent Jackson version.","Retry the query; if transient, the offset write will succeed on the next micro-batch.","If reproducible, report with the full stack trace; the serialization target is an in-memory StringWriter so repeated failure signals an environment problem."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  String json = offset.json();\n} catch (UncheckedIOException e) {\n  logger.error(\"StreamingOffset serialization failed; check Jackson classpath\", e);\n}","preventionTips":["Keep a single consistent Jackson version on the classpath.","Avoid shading conflicts between Spark and Iceberg Jackson versions.","Monitor the checkpoint write path for transient JVM failures."],"tags":["spark","structured-streaming","json","serialization"],"backgroundTag":"json-serialization-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}