diff options
author | James Moger <james.moger@gitblit.com> | 2015-04-22 16:34:30 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2015-04-22 16:34:30 -0400 |
commit | 8ac32ab5469d3da41104f91a1c08616a1e1928fb (patch) | |
tree | c6cf2b59a0f02a34a4734e7bf581ada94a8868bc | |
parent | e670abca93ddc6455ab75a01cfdd07abc3b3e9ad (diff) | |
download | iciql-8ac32ab5469d3da41104f91a1c08616a1e1928fb.tar.gz iciql-8ac32ab5469d3da41104f91a1c08616a1e1928fb.zip |
Fix deserialization of null values
-rw-r--r-- | src/main/java/com/iciql/SQLDialectDefault.java | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/main/java/com/iciql/SQLDialectDefault.java b/src/main/java/com/iciql/SQLDialectDefault.java index 7b4852d..19b0fcd 100644 --- a/src/main/java/com/iciql/SQLDialectDefault.java +++ b/src/main/java/com/iciql/SQLDialectDefault.java @@ -477,39 +477,32 @@ public class SQLDialectDefault implements SQLDialect { @Override public Object deserialize(ResultSet rs, int columnIndex, Class<?> targetType) { - DataTypeAdapter<?> dta = getAdapter(targetType); - if (dta == null) { - // standard object deserialization - Object value = null; - try { - // use internal Iciql type conversion + Object value = null; + try { + DataTypeAdapter<?> dta = getAdapter(targetType); + if (dta == null) { + // standard object deserialization Object o = rs.getObject(columnIndex); - if (Clob.class.isAssignableFrom(o.getClass())) { + if (o == null) { + // no-op + value = null; + } else if (Clob.class.isAssignableFrom(o.getClass())) { value = Utils.convert(o, String.class); } else if (Blob.class.isAssignableFrom(o.getClass())) { value = Utils.convert(o, byte[].class); } else { value = Utils.convert(o, targetType); } - } catch (SQLException e) { - throw new IciqlException(e, "Can not convert the value at column {0} to {1}", - columnIndex, targetType.getName()); - } - - return value; - } else { - // custom object deserialization with a DataTypeAdapter - Object object = null; - try { - object = rs.getObject(columnIndex); - } catch (SQLException e) { - throw new IciqlException(e, "Can not convert the value at column {0} to {1}", - columnIndex, targetType.getName()); + } else { + // custom object deserialization with a DataTypeAdapter + Object object = rs.getObject(columnIndex); + value = dta.deserialize(object); } - - Object value = dta.deserialize(object); - return value; + } catch (SQLException e) { + throw new IciqlException(e, "Can not convert the value at column {0} to {1}", + columnIndex, targetType.getName()); } + return value; } @Override |