From 3b5f8b50e7191a3c514e93e46f724f561520b032 Mon Sep 17 00:00:00 2001 From: Morten Kjetland Date: Sun, 17 Mar 2013 21:09:35 +0100 Subject: [PATCH] Fixes #52 Improved null-handling when reading many primitives --- .../java/redis/clients/johm/JOhmUtils.java | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/redis/clients/johm/JOhmUtils.java b/src/main/java/redis/clients/johm/JOhmUtils.java index 235aa7a..5d0820c 100644 --- a/src/main/java/redis/clients/johm/JOhmUtils.java +++ b/src/main/java/redis/clients/johm/JOhmUtils.java @@ -215,25 +215,64 @@ public static Object convert(final Class type, final String value) { return '\u0000'; } } - if (type.equals(Short.class) || type.equals(short.class)) { + if (type.equals(short.class)) { + if ( value == null) { + return 0; + } + return new Short(value); + } + if (type.equals(Short.class)) { + if ( value == null) { + return null; + } return new Short(value); } - if (type.equals(Integer.class) || type.equals(int.class)) { + if (type.equals(int.class)) { if (value == null) { return 0; } return new Integer(value); } - if (type.equals(Float.class) || type.equals(float.class)) { + if (type.equals(Integer.class)) { + if (value == null) { + return null; + } + return new Integer(value); + } + if (type.equals(float.class)) { if (value == null) { return 0f; } return new Float(value); } - if (type.equals(Double.class) || type.equals(double.class)) { + if (type.equals(Float.class)) { + if (value == null) { + return null; + } + return new Float(value); + } + if (type.equals(double.class)) { + if ( value == null) { + return 0.0; + } + return new Double(value); + } + if (type.equals(Double.class)) { + if ( value == null ) { + return null; + } return new Double(value); } - if (type.equals(Long.class) || type.equals(long.class)) { + if (type.equals(long.class)) { + if ( value == null) { + return 0L; + } + return new Long(value); + } + if (type.equals(Long.class)) { + if ( value == null) { + return null; + } return new Long(value); } if (type.equals(Boolean.class) || type.equals(boolean.class)) {