arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
435 stars 76 forks source link

Postgres UUID array mapping #731

Open IvoMajic opened 3 years ago

IvoMajic commented 3 years ago

I have a Postgres column with a UUID array, in the class

ResultSetGetterFactory {

        factoryRegistry.put(UUID.class, new GetterFactory<ResultSet, JdbcColumnKey>() { ... }

}

the column type is mapped to JdbcColumnKey.UNDEFINED_TYPE, so the deserialization fails as the type is already a UUID object and UUIDUnspecifiedTypeGetter does not have that option in its switch case.

Interestingly in the same file below, we have this:

case Types.OTHER:
        // assume it's a UUID postgres
        return (Getter<ResultSet, P>) new ObjectResultSetGetter(key.getIndex());

But the JDBCColumn was never mapped to Types.OTHER

The exception:

java.lang.IllegalArgumentException: Cannot convert 79384f39-42f3-4dd8-995d-8580d59d72e2 to UUID at org.simpleflatmapper.reflect.getter.UUIDUnspecifiedTypeGetter.get(UUIDUnspecifiedTypeGetter.java:29)

In my record class it properly marked as

    public void setImages(UUID[] value) {
        set(8, value);
    }

    public UUID[] getImages() {
        return (UUID[]) get(8);
    }

For now, I managed to work around it by adding a custom column property like this to the mapper (Kotlin syntax)

addColumnProperty(
        Predicate { columnKey: JdbcColumnKey ->
                columnKey.name == "images"
        },
        SqlTypeColumnProperty.of(Types.OTHER)
)