{"record":{"id":"d0a502dc2efc52e3","repo":"apache/beam","slug":"cannot-provide-serializablecoder-because-does-not-implement","errorCode":null,"errorMessage":"Cannot provide SerializableCoder because {} does not implement Serializable","messagePattern":"Cannot provide SerializableCoder because (.+?) does not implement Serializable","errorType":"exception","errorClass":"CannotProvideCoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/SerializableCoder.java","lineNumber":163,"sourceCode":"    @Override\n    public List<CoderProvider> getCoderProviders() {\n      return ImmutableList.of(getCoderProvider());\n    }\n  }\n\n  /**\n   * A {@link CoderProvider} that constructs a {@link SerializableCoder} for any class that\n   * implements serializable.\n   */\n  static class SerializableCoderProvider extends CoderProvider {\n    @Override\n    public <T> Coder<T> coderFor(\n        TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders)\n        throws CannotProvideCoderException {\n      if (Serializable.class.isAssignableFrom(typeDescriptor.getRawType())) {\n        return SerializableCoder.of((TypeDescriptor) typeDescriptor);\n      }\n      throw new CannotProvideCoderException(\n          \"Cannot provide SerializableCoder because \"\n              + typeDescriptor\n              + \" does not implement Serializable\");\n    }\n  }\n\n  private final Class<T> type;\n\n  /**\n   * Access via {@link #getEncodedTypeDescriptor()}.\n   *\n   * <p>The field is restored lazily if it is not present due to serialization.\n   */\n  @SuppressFBWarnings(\"SE_TRANSIENT_FIELD_NOT_RESTORED\")\n  private transient @Nullable TypeDescriptor<T> typeDescriptor;\n\n  protected SerializableCoder(Class<T> type, TypeDescriptor<T> typeDescriptor) {\n    this.type = type;","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/SerializableCoder.java#L145-L181","documentation":"SerializableCoder's CoderProvider (coderFor) can only supply coders for types implementing java.io.Serializable. When the CoderRegistry falls back to SerializableCoder for a type that isn't Serializable, it throws CannotProvideCoderException with this message. The registry then tries other providers or fails pipeline construction.","triggerScenarios":"Registering a type for which no other coder provider matches and the raw type does not implement Serializable; using CoderRegistry.getCoder(TypeDescriptor) for a POJO missing `implements Serializable`.","commonSituations":"POJOs/records used as PCollection elements without Serializable; refactoring a class to drop Serializable; using third-party types as pipeline elements.","solutions":["Make the type implement java.io.Serializable","Register an explicit coder: pipeline.getCoderRegistry().registerCoderForType(descriptor, MyCustomCoder.of(...))","Use AvroCoder, RowCoder, or a schema-based coder instead of SerializableCoder","If it's an immutable value type, implement a custom deterministic Coder<T>"],"exampleFix":"// before\nclass MyKey { String id; } // not Serializable -> CannotProvideCoderException\n// after\nclass MyKey implements Serializable { String id; }","handlingStrategy":"validation","validationCode":"if (!Serializable.class.isAssignableFrom(MyKey.class)) { /* register explicit coder or make it Serializable */ }","typeGuard":"boolean isSerializable(Class<?> c) { return Serializable.class.isAssignableFrom(c); }","tryCatchPattern":"try { Coder<T> c = registry.getCoder(TypeDescriptor.of(MyType.class)); } catch (CannotProvideCoderException e) { registry.registerCoderForType(descriptor, myCustomCoder); }","preventionTips":["Have all PCollection element types implement Serializable, or register explicit coders","Prefer Avro/Row coders over Serializable for new pipelines","Run CoderRegistry resolution in unit tests before submitting jobs"],"tags":["java","beam","coders","serialization"],"backgroundTag":"incompatible-source-type","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"}