{"record":{"id":"abf2a7e04866a09f","repo":"apache/hadoop","slug":"cannot-serialize-type-we-only-accept-subclass","errorCode":null,"errorMessage":"Cannot serialize type {}, we only accept subclass of Writable","messagePattern":"Cannot serialize type (.+?), we only accept subclass of Writable","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/main/java/org/apache/hadoop/mapred/nativetask/serde/NativeSerialization.java","lineNumber":44,"sourceCode":"\n@InterfaceAudience.Private\npublic class NativeSerialization {\n\n  private final ConcurrentHashMap<String, Class<?>> map =\n    new ConcurrentHashMap<String, Class<?>>();\n\n  public boolean accept(Class<?> c) {\n    return Writable.class.isAssignableFrom(c);\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  public INativeSerializer<Writable> getSerializer(Class<?> c) throws IOException {\n\n    if (null == c) {\n      return null;\n    }\n    if (!Writable.class.isAssignableFrom(c)) {\n      throw new IOException(\"Cannot serialize type \" + c.getName() +\n                            \", we only accept subclass of Writable\");\n    }\n    final String name = c.getName();\n    final Class<?> serializer = map.get(name);\n\n    if (null != serializer) {\n      try {\n        return (INativeSerializer<Writable>) serializer.newInstance();\n      } catch (final Exception e) {\n        throw new IOException(e);\n      }\n    }\n    return new DefaultSerializer();\n  }\n\n  public void register(String klass, Class<?> serializer) throws IOException {\n    if (null == klass || null == serializer) {\n      throw new IOException(\"invalid arguments, klass or serializer is null\");","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/main/java/org/apache/hadoop/mapred/nativetask/serde/NativeSerialization.java#L26-L62","documentation":"Error \"Cannot serialize type {}, we only accept subclass of Writable\" thrown in apache/hadoop.","triggerScenarios":"Thrown by NativeSerialization.register() when asked to serialize a class that is not a subclass of Writable. Only Writable types can be registered with the nativetask serialization framework; implement Writable or use the Java collector.","commonSituations":"Job configured with a non-Writable key/value class while mapreduce.map.output.collector.delegator / native task is enabled.","solutions":["Use key/value classes that extend org.apache.hadoop.io.Writable for native tasks.","If a custom type is needed, implement Writable (or register a native serializer) instead of a plain Java type."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}