{"record":{"id":"486a55b95c393cdf","repo":"apache/seatunnel","slug":"illegal-argument-486a55","errorCode":"ILLEGAL_ARGUMENT","errorMessage":"Unable to convert to LocalDateTime from unexpected value '${bsonValue}' of type ${bsonValue.getBsonType()}","messagePattern":"Unable to convert to LocalDateTime from unexpected value '(.+?)' of type (.+?)","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/BsonToRowDataConverters.java","lineNumber":232,"sourceCode":"                return createMapConverter(\n                        mapType.toString(), mapType.getKeyType(), mapType.getValueType());\n\n            case ROW:\n                return createRowConverter((SeaTunnelRowType) type);\n            default:\n                throw new MongodbConnectorException(\n                        UNSUPPORTED_DATA_TYPE, \"Not support to parse type: \" + type);\n        }\n    }\n\n    private static LocalDateTime convertToLocalDateTime(BsonValue bsonValue) {\n        Instant instant;\n        if (bsonValue.isTimestamp()) {\n            instant = Instant.ofEpochMilli(bsonValue.asTimestamp().getValue());\n        } else if (bsonValue.isDateTime()) {\n            instant = Instant.ofEpochMilli(bsonValue.asDateTime().getValue());\n        } else {\n            throw new MongodbConnectorException(\n                    ILLEGAL_ARGUMENT,\n                    \"Unable to convert to LocalDateTime from unexpected value '\"\n                            + bsonValue\n                            + \"' of type \"\n                            + bsonValue.getBsonType());\n        }\n        return Timestamp.from(instant).toLocalDateTime();\n    }\n\n    private static SerializableFunction<BsonValue, Object> createRowConverter(\n            SeaTunnelRowType type) {\n        SeaTunnelDataType<?>[] fieldTypes = type.getFieldTypes();\n        final SerializableFunction<BsonValue, Object>[] fieldConverters =\n                Arrays.stream(fieldTypes)\n                        .map(BsonToRowDataConverters::createNullSafeInternalConverter)\n                        .toArray(SerializableFunction[]::new);\n        int fieldCount = type.getTotalFields();\n","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/BsonToRowDataConverters.java#L214-L250","documentation":"convertToLocalDateTime converts a BsonValue into LocalDateTime, accepting only BSON Timestamp and BSON Date. Any other BsonType (string, int, null-like BsonNull, object, etc.) cannot become a timestamp, so it throws MongodbConnectorException(ILLEGAL_ARGUMENT) describing the offending value and its BSON type.","triggerScenarios":"A column is declared TIMESTAMP (or DATE) in the SeaTunnel schema but the actual MongoDB document stores the field as a string (e.g. \"2024-01-01T00:00:00Z\"), a number, or BsonNull; apply() then calls convertToLocalDateTime which hits the else branch.","commonSituations":"Schema defined as TIMESTAMP while documents hold ISO-8601 strings written by another tool; mixed-type collections where some documents have the field missing (BsonNull) or of a different BSON type.","solutions":["Make the documents store the field as a real BSON Date (or Timestamp) type.","Re-declare the column as STRING in the schema and parse the date downstream.","Clean/normalize the collection so all documents use a consistent BSON Date type for the field.","Filter out or null-safe documents whose field is BsonNull before conversion."],"exampleFix":"// before (mongo doc)\n{ \"created_at\": \"2024-01-01T00:00:00Z\" }\n// after\n{ \"created_at\": ISODate(\"2024-01-01T00:00:00Z\") }","handlingStrategy":"validation","validationCode":"// Run this against the collection before reading with a TIMESTAMP column\ndb.coll.find({ created_at: { $not: { $type: { $in: [\"date\", \"timestamp\"] } } } }).limit(1)\n// Returns documents that would trigger the error; result should be empty","typeGuard":"static boolean isBsonTemporal(org.bson.BsonValue v) {\n    return v != null && (v.isDateTime() || v.isTimestamp());\n}","tryCatchPattern":"try {\n    convertToLocalDateTime(bsonValue);\n} catch (MongodbConnectorException e) {\n    if (e.getMessage().startsWith(\"Unable to convert to LocalDateTime\")) {\n        // treat as null / fallback to string parsing of the raw value\n    } else { throw e; }\n}","preventionTips":["Always write real BSON Date/Timestamp types for temporal fields (new Date(...) in drivers, not strings)","Validate mixed-type collections with a $type query before mapping to TIMESTAMP","Declare the column as STRING if upstream tools write ISO-8601 text"],"tags":["mongodb","sea-tunnel","serde","date-conversion","type-mismatch"],"backgroundTag":"invalid-date-format","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"}