{"record":{"id":"354092af46afce5f","repo":"apache/iceberg","slug":"unexpected-type-type-for-field-fieldname","errorCode":null,"errorMessage":"Unexpected type ${type} for field ${fieldName}","messagePattern":"Unexpected type (.+?) for field (.+?)","errorType":"exception","errorClass":"JsonToMapException","httpStatus":null,"severity":"error","filePath":"kafka-connect/kafka-connect-transforms/src/main/java/org/apache/iceberg/connect/transforms/JsonToMapUtils.java","lineNumber":259,"sourceCode":"        obj = node.longValue();\n        break;\n      case FLOAT32:\n        obj = node.floatValue();\n        break;\n      case FLOAT64:\n        obj = node.doubleValue();\n        break;\n      case MAP:\n        ObjectNode mapNode = (ObjectNode) node;\n        Map<String, String> map = Maps.newHashMap();\n        populateMap(mapNode, map);\n        obj = map;\n        break;\n      case BYTES:\n        obj = extractBytes(node, fieldName);\n        break;\n      default:\n        throw new JsonToMapException(\n            String.format(\"Unexpected type %s for field %s\", type, fieldName));\n    }\n    return obj;\n  }\n\n  private static Object extractBytes(JsonNode node, String fieldName) {\n    Object obj;\n    try {\n      if (node.isBigInteger()) {\n        obj = new BigDecimal(node.bigIntegerValue());\n      } else if (node.isBigDecimal()) {\n        obj = node.decimalValue();\n      } else {\n        obj = node.binaryValue();\n      }\n    } catch (Exception e) {\n      throw new JsonToMapException(\n          String.format(\"parsing binary value threw exception for %s\", fieldName), e);","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/kafka-connect/kafka-connect-transforms/src/main/java/org/apache/iceberg/connect/transforms/JsonToMapUtils.java#L241-L277","documentation":"JsonToMapUtils.extractValue throws JsonToMapException when the requested Schema Type for a field is not one of the handled types (STRING, INTEGER, etc., or BYTES). The transform only knows how to convert JSON nodes into a fixed set of Kafka Connect types, so an unhandled type in the target map/struct schema is rejected.","triggerScenarios":"Calling the JsonConverter-based transform with a target schema whose field has a Type that falls into the `default` branch of extractValue's switch — e.g. a MAP or custom logical type — while populating the struct via addToStruct or populateArray.","commonSituations":"Users apply the JsonToMap transform on records whose value schema contains types the converter does not support (e.g. nested map types or logical timestamp types), often after changing the target schema or upgrading the connector.","solutions":["Inspect the record's value schema and change the unsupported field's type to one supported by the transform (STRING, INT, BYTES, etc.).","Flatten or cast the offending field upstream (e.g. with a different SMT) before applying the transform.","Extend extractValue with a case for the needed type if you control the code."],"exampleFix":"// before\nSchema fieldSchema = SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.FLOAT64_SCHEMA).build();\n// after — use a supported scalar type\nSchema fieldSchema = SchemaBuilder.string().build();","handlingStrategy":"validation","validationCode":"// Pre-check schema fields against supported types before applying the transform\njava.util.Set<org.apache.kafka.connect.data.Schema.Type> supported = java.util.Set.of(\n    Schema.Type.STRING, Schema.Type.INT8, Schema.Type.INT16, Schema.Type.INT32,\n    Schema.Type.INT64, Schema.Type.FLOAT32, Schema.Type.FLOAT64, Schema.Type.BOOLEAN, Schema.Type.BYTES);\nfor (Field f : record.valueSchema().fields()) {\n  if (!supported.contains(f.schema().type())) throw new IllegalStateException(\"unsupported type \" + f.schema().type() + \" for field \" + f.name());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep target schemas limited to scalar Connect types when using JSON-to-map transforms","Test transforms against representative records before deploying","Log valueSchema().type() for each field when debugging"],"tags":["kafka-connect","json","type-mismatch"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}