{"record":{"id":"da00992c6bb1a606","repo":"apache/seatunnel","slug":"unsupported-operation-da0099","errorCode":"UNSUPPORTED_OPERATION","errorMessage":"JSON format doesn't support non-string as key type of map. The type is: ${typeSummary}","messagePattern":"JSON format doesn't support non-string as key type of map\\. The type is: (.+?)","errorType":"error_code","errorClass":"MongodbConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/RowDataToBsonConverters.java","lineNumber":279,"sourceCode":"        return new SerializableFunction<Object, BsonValue>() {\n            private static final long serialVersionUID = 1L;\n\n            @Override\n            public BsonValue apply(Object value) {\n                Object[] arrayData = (Object[]) value;\n                final List<BsonValue> bsonValues = new ArrayList<>();\n                for (Object element : arrayData) {\n                    bsonValues.add(elementConverter.apply(element));\n                }\n                return new BsonArray(bsonValues);\n            }\n        };\n    }\n\n    private static SerializableFunction<Object, BsonValue> createMapConverter(\n            String typeSummary, SeaTunnelDataType<?> keyType, SeaTunnelDataType<?> valueType) {\n        if (!SqlType.STRING.equals(keyType.getSqlType())) {\n            throw new MongodbConnectorException(\n                    CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION,\n                    \"JSON format doesn't support non-string as key type of map. The type is: \"\n                            + typeSummary);\n        }\n\n        final SerializableFunction<Object, BsonValue> valueConverter =\n                createNullSafeInternalConverter(valueType);\n\n        return new SerializableFunction<Object, BsonValue>() {\n            private static final long serialVersionUID = 1L;\n\n            @Override\n            public BsonValue apply(Object value) {\n                Map<String, ?> mapData = (Map<String, ?>) value;\n                final BsonDocument document = new BsonDocument();\n                for (Map.Entry<String, ?> entry : mapData.entrySet()) {\n                    String fieldName = entry.getKey();\n                    document.append(fieldName, valueConverter.apply(entry.getValue()));","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/RowDataToBsonConverters.java#L261-L297","documentation":"The MongoDB sink's JSON/BSON serialization layer rejects map types whose keys are not strings. BSON (and JSON) documents require field names to be strings, so any SeaTunnel MAP with a non-STRING key type (e.g. MAP<INT,STRING>) cannot be converted to a BSON document. The converter is built once per row type at sink initialization, so this fails fast when the converter is created.","triggerScenarios":"Defining a SeaTunnel MAP field whose key SqlType is not STRING (e.g. MAP<Int, String>, MAP<Long, String>) and writing it to the MongoDB sink via createMapConverter.","commonSituations":"Users modeling keyed data with integer IDs (e.g. MAP<INT,STRING>) coming from relational sources or inline schemas; upstream schema inference produced integer map keys; hand-written schema in the config used a non-string key.","solutions":["Change the map key type to STRING in the SeaTunnel schema (e.g. MAP<STRING,STRING>) at the source or via a transform.","Insert a transform that converts the offending map field to a JSON string or re-keys it as strings before the MongoDB sink.","If integer keys are required, flatten the map into separate fields or store as an array of key/value documents instead."],"exampleFix":"// before (schema)\nfields { id = INT payload = MAP<INT, STRING> }\n// after\nfields { id = INT payload = MAP<STRING, STRING> }","handlingStrategy":"validation","validationCode":"if (mapType.getKeyType().getSqlType() != SqlType.STRING) {\n    throw new IllegalArgumentException(\n        \"MongoDB sink requires MAP keys of type STRING, got: \" + mapType.getKeyType());\n}","typeGuard":"static boolean hasStringMapKeys(SeaTunnelRowType rowType) {\n    return java.util.Arrays.stream(rowType.getFieldTypes())\n        .filter(t -> t instanceof SeaTunnelMapType)\n        .map(t -> (SeaTunnelMapType<?, ?>) t)\n        .allMatch(m -> m.getKeyType().getSqlType() == SqlType.STRING);\n}","tryCatchPattern":null,"preventionTips":["Always declare MAP fields with STRING keys when targeting MongoDB.","Review source schema inference output before wiring to the MongoDB sink.","Add a transform stage to stringify maps with non-string keys."],"tags":["mongodb","serialization","map-type","schema"],"backgroundTag":"unsupported-operation","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}