]> source.dussan.org Git - iciql.git/commitdiff
Fix deserialization of null values
authorJames Moger <james.moger@gitblit.com>
Wed, 22 Apr 2015 20:34:30 +0000 (16:34 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 22 Apr 2015 20:34:30 +0000 (16:34 -0400)
src/main/java/com/iciql/SQLDialectDefault.java

index 7b4852d16fbd566c8959a305dcf8106c49204311..19b0fcd4a911b12e63bb1dd671f05b2b39cbfb7a 100644 (file)
@@ -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