Commits

Anonymous committed 685bfde

Fixing type conversion issue: field errors were added when empty strings were passed in for basic types. XworkBasicConverter now checks for empty Strings and sets null without adding an error.

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@69e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (1)

src/java/com/opensymphony/xwork/util/XWorkBasicConverter.java

  * @version $Revision$
  */
 public class XWorkBasicConverter extends DefaultTypeConverter {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Object OK_NULL_RESULT = new Object();
+
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public Object convertValue(Map context, Object o, Member member, String s, Object value, Class toType) {
         Object result = null;
 
+        //short circuit conversion for empty strings... these are not conversion errors
+        if ("".equals(value)) {
+            result = (String.class.equals(toType)) ? "" : OK_NULL_RESULT;
+
+            return result;
+        }
+
         if (toType == String.class) {
             result = doConvertToString(context, value);
         } else if (toType == boolean.class) {
             throw new TypeConversionException("Unable to convert value '" + value + "' to type " + toType.getName());
         }
 
+        if (result == OK_NULL_RESULT) {
+            return null;
+        }
+
         return result;
     }