apache/seatunnel · error · UnsupportedOperationException

Unsupported convert to LocalDate, typeDefine

Error message

Unsupported convert ${value.getClass()} to LocalDate, typeDefine: ${typeDefine}

What it means

convertLocalDate(TypeDefine, Object) supports String, Number (epoch day/millis depending on config) and temporal instances; any other class triggers UnsupportedOperationException with the typeDefine included. It means the field's runtime type has no LocalDate conversion rule in the converter.

Solutions

  1. Identify the class from the message and pre-convert to java.time.LocalDate, an ISO-8601 date String, or a Number epoch
  2. Add a custom DataConverter for the offending class if it is consistently produced by the source
  3. Correct the schema mapping so the source field type matches DATE expectations

Example fix

// before
converter.convert(dateTypeDefine, bsonDateTime); // org.bson.BsonDateTime
// after
LocalDate d = Instant.ofEpochMilli(((org.bson.BsonDateTime) bsonDateTime).getValue())
    .atZone(ZoneId.systemDefault()).toLocalDate();
converter.convert(dateTypeDefine, d);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(v instanceof Number) && !(v instanceof String) && !(v instanceof java.time.temporal.TemporalAccessor) && !(v instanceof java.util.Date)) {
    throw new IllegalStateException("Unsupported date class: " + v.getClass());
}

Type guard

boolean isDateLike(Object v) {
    return v instanceof Number || v instanceof String
        || v instanceof java.time.temporal.TemporalAccessor
        || v instanceof java.util.Date;
}

Try / catch

try {
    converter.convert(typeDefine, value);
} catch (UnsupportedOperationException e) {
    LOG.warn("Date conversion failed for {}: {}", value.getClass(), e.getMessage());
    value = normalizeToDate(value);
}

Prevention

When it happens

Trigger: Calling convert() for a DATE-mapped column with an unhandled class such as byte[], a BSON date wrapper, or a domain object, when neither the String nor Number branch applies.

Common situations: MongoDB/NoSQL drivers returning custom date types; schema drift after connector upgrade changing the deserialized class; passing an epoch value wrapped in a non-Number type like String that isn't ISO-formatted (though String usually routes to parsing).

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/5f7909438b45baf1. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-api/src/main/java/org/apache/seatunnel/api/table/converter/BasicDataConverter.java:750

        if (value instanceof LocalDate) {
            return (LocalDate) value;
        }
        if (value instanceof Date) {
            return convertLocalDate(typeDefine, (Date) value);
        }
        if (value instanceof LocalDateTime) {
            return ((LocalDateTime) value).toLocalDate();
        }
        if (value instanceof java.sql.Date) {
            return ((java.sql.Date) value).toLocalDate();
        }
        if (value instanceof String) {
            return convertLocalDate(typeDefine, (String) value);
        }
        if (value instanceof Number) {
            return convertLocalDate(typeDefine, (Number) value);
        }
        throw new UnsupportedOperationException(
                "Unsupported convert "
                        + value.getClass()
                        + " to LocalDate, typeDefine: "
                        + typeDefine);
    }

    default LocalDate convertLocalDate(T typeDefine, Date value) {
        return convertLocalDate(value);
    }

    default LocalDate convertLocalDate(T typeDefine, String value) {
        return convertLocalDate(value);
    }

    default LocalDate convertLocalDate(T typeDefine, Number value) {
        return convertLocalDate(value);
    }

View on GitHub (pinned to cf67b549a7)