{"record":{"id":"b0cb955e553cd28e","repo":"apache/beam","slug":"unable-to-infer-coder-for-output-of-parsefn-specify-it-b0cb95","errorCode":null,"errorMessage":"Unable to infer coder for output of parseFn. Specify it explicitly using withCoder().","messagePattern":"Unable to infer coder for output of parseFn\\. Specify it explicitly using withCoder\\(\\)\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java","lineNumber":1380,"sourceCode":"       * are available, usually within a few minutes. Batch queries don't count towards your\n       * concurrent rate limit.\n       */\n      BATCH\n    }\n\n    @VisibleForTesting\n    Coder<T> inferCoder(CoderRegistry coderRegistry) {\n      Coder<T> coder = getCoder();\n      if (coder != null) {\n        return coder;\n      }\n\n      try {\n        return coderRegistry.getCoder(\n            TypeDescriptors.outputOf(\n                checkStateNotNull(getParseFn(), \"Either withCoder() or a parseFn is required\")));\n      } catch (CannotProvideCoderException e) {\n        throw new IllegalArgumentException(\n            \"Unable to infer coder for output of parseFn. Specify it explicitly using withCoder().\",\n            e);\n      }\n    }\n\n    private BigQuerySourceDef createSourceDef() {\n      ValueProvider<String> query = getQuery();\n      if (query == null) {\n        return BigQueryTableSourceDef.create(\n            getBigQueryServices(),\n            checkStateNotNull(getTableProvider(), \"Either from() or fromQuery() is required\"));\n      }\n      return BigQueryQuerySourceDef.create(\n          getBigQueryServices(),\n          query,\n          checkStateNotNull(\n              getFlattenResults(), \"flattenResults should not be null if query is set\"),\n          checkStateNotNull(getUseLegacySql(), \"useLegacySql should not be null if query is set\"),","sourceCodeStart":1362,"sourceCodeEnd":1398,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java#L1362-L1398","documentation":"BigQueryIO.TypedRead.inferCoder tries to derive the output Coder from the parseFn's generic type via the CoderRegistry. When neither withCoder() was called nor a Coder can be inferred from the parseFn's type signature (CannotProvideCoderException), this IllegalArgumentException fires, telling the user to supply a coder explicitly.","triggerScenarios":"BigQueryIO.read().withParseFn(parseFn) where parseFn's output type is a custom class with no registered default coder and .withCoder() was not called.","commonSituations":"Returning custom POJOs or classes without @DefaultSchema/AvroTypeSupplier; using lambdas whose generic type info is erased; missing coder registration for the target type.","solutions":["Call .withCoder(SerializableCoder.of(MyType.class)) explicitly on the read","Register a default coder for the type via CoderRegistry","Use a supported type (TableRow, TableRecord with schema annotation) so inference works"],"exampleFix":"// before\nBigQueryIO.read(parseFn).from(\"proj:ds.tbl\");\n// after\nBigQueryIO.read(parseFn).from(\"proj:ds.tbl\").withCoder(SerializableCoder.of(MyRecord.class));","handlingStrategy":"validation","validationCode":"// Ensure a coder can be inferred before building the pipeline\ntry {\n  pipeline.getCoderRegistry().getCoder(TypeDescriptors.outputOf(parseFn));\n} catch (CannotProvideCoderException e) {\n  throw new IllegalStateException(\"Register a coder or call withCoder()\", e);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call .withCoder(SerializableCoder.of(...)) for custom output types","Avoid raw lambdas where generic type information is erased","Annotate POJOs with @DefaultSchema or register default coders"],"tags":["bigquery","coder","serialization","java"],"backgroundTag":"missing-required-argument","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"}