{"record":{"id":"2b7107a80d664f95","repo":"apache/iceberg","slug":"cannot-serialize-type-typeid","errorCode":null,"errorMessage":"Cannot serialize type: + typeId","messagePattern":"Cannot serialize type: \\+ typeId","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/types/Conversions.java","lineNumber":145,"sourceCode":"        VariantMetadata variantMetadata = variant.metadata();\n        VariantValue variantValue = variant.value();\n        ByteBuffer variantBuffer =\n            ByteBuffer.allocate(variantMetadata.sizeInBytes() + variantValue.sizeInBytes())\n                .order(ByteOrder.LITTLE_ENDIAN);\n        variantMetadata.writeTo(variantBuffer, 0);\n        variantValue.writeTo(variantBuffer, variantMetadata.sizeInBytes());\n        return variantBuffer;\n      case GEOMETRY:\n      case GEOGRAPHY:\n        // Geometry and geography lower/upper bounds are single points encoded as an\n        // x:y:z:m concatenation of 8-byte little-endian IEEE 754 doubles. See the\n        // Bound Serialization section of the Iceberg spec.\n        return ((GeospatialBound) value).toByteBuffer();\n      case UNKNOWN:\n        // underlying type not known\n        return null;\n      default:\n        throw new UnsupportedOperationException(\"Cannot serialize type: \" + typeId);\n    }\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  public static <T> T fromByteBuffer(Type type, ByteBuffer buffer) {\n    return (T) internalFromByteBuffer(type, buffer);\n  }\n\n  private static Object internalFromByteBuffer(Type type, ByteBuffer buffer) {\n    if (buffer == null) {\n      return null;\n    }\n\n    ByteBuffer tmp = buffer.duplicate();\n    if (type == Types.UUIDType.get() || type instanceof Types.DecimalType) {\n      tmp.order(ByteOrder.BIG_ENDIAN);\n    } else {\n      tmp.order(ByteOrder.LITTLE_ENDIAN);","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/types/Conversions.java#L127-L163","documentation":"Conversions.toByteBuffer maps each primitive typeId to its spec-defined binary encoding and throws UnsupportedOperationException for typeIds it cannot serialize. This happens for types with no serialization definition in this client version (e.g. unknown/unsupported new spec types) or for a value passed with a mismatched typeId.","triggerScenarios":"Serializing a value whose typeId falls into the default branch — typically UNKNOWN types or a spec type (variant, new geo kinds) added after this Iceberg version; passing the wrong Type alongside a value.","commonSituations":"Writing statistics/partition values containing fields of newer spec types with an older client; generic serialization code that iterates all fields of a schema including unserializable ones.","solutions":["Upgrade the Iceberg version to one that serializes the type","Skip fields whose typeId is unsupported before calling toByteBuffer","Ensure the Type passed matches the actual value's type"],"exampleFix":"// before\nfor (Types.NestedField f : schema.columns()) {\n  Object ser = Conversions.toByteBuffer(f.type(), values.get(f.fieldId())); // throws for unknown\n}\n// after\nfor (Types.NestedField f : schema.columns()) {\n  if (f.type() instanceof Types.UnknownType) continue;\n  Object ser = Conversions.toByteBuffer(f.type(), values.get(f.fieldId()));\n}","handlingStrategy":"validation","validationCode":"if (type.typeId() == Type.TypeID.UNKNOWN) skip; else serialize;","typeGuard":"boolean serializable(Type t) { return t.typeId() != Type.TypeID.UNKNOWN; }","tryCatchPattern":"try { buf = Conversions.toByteBuffer(type, v); } catch (UnsupportedOperationException e) { buf = null; }","preventionTips":["Skip UNKNOWN/newer spec types when serializing statistics","Keep client versions current with the spec","Match the Type argument exactly to the value's declared field type"],"tags":["java","serialization","conversions","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}