You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by Steve Quint <li...@nanohertz.com> on 2004/04/24 00:47:45 UTC

PATCH: src/java/org/apache/xmlrpc/DefaultTypeFactory.java

I've recently had to interface with a system that will remain un-named here that was generating XMLRPC responses that had null values for an integer field.

I figured setting reasonable defaults for integers, doubles, and booleans is probably better than having the entire XMLRPC transaction blow up.  This patch will create Integer and Double objects with "0" as the default value, and Boolean objects with "false" as the default value.

----------
Index: src/java/org/apache/xmlrpc/DefaultTypeFactory.java
===================================================================
RCS file: /home/cvspublic/ws-xmlrpc/src/java/org/apache/xmlrpc/DefaultTypeFactory.java,v
retrieving revision 1.3
diff -u -r1.3 DefaultTypeFactory.java
--- src/java/org/apache/xmlrpc/DefaultTypeFactory.java	1 May 2003 16:53:15 -0000	1.3
+++ src/java/org/apache/xmlrpc/DefaultTypeFactory.java	23 Apr 2004 22:19:20 -0000
@@ -98,19 +98,44 @@
 
     public Object createInteger(String cdata)
     {
-        return new Integer(cdata.trim());
+        Integer val;
+        if ( cdata == null || cdata.equals( "" ) )
+        {
+            val = new Integer( 0 );
+        }
+        else
+        {
+            val = new Integer(cdata.trim());
+        }
+        return val;
     }
 
     public Object createBoolean(String cdata)
     {
-        return ("1".equals(cdata.trim ())
-               ? Boolean.TRUE : Boolean.FALSE);
+        Boolean val;
+        if ( cdata == null || cdata.equals( "" ) )
+        {
+            val = Boolean.FALSE;
+        }
+        else
+        {
+            val = "1".equals(cdata.trim ()) ? Boolean.TRUE : Boolean.FALSE;
+        }
+        return val;
     }
 
     public Object createDouble(String cdata)
     {
-        return new Double(cdata.trim ());
-
+        Double val;
+        if ( cdata == null || cdata.equals( "" ) )
+        {
+            val = new Double( 0 );
+        }
+        else
+        {
+            val = new Double(cdata.trim ());
+        }
+        return val;
     }
 
     public Object createDate(String cdata)

-- 

Steve

------------------------------------------------------------
"Always ... always remember: Less is less. More is more. More is
better. And twice as much is good too. Not enough is bad. And too
much is never enough except when it's just about right."
			-- The Tick
------------------------------------------------------------