[jboss-svn-commits] JBoss Common SVN: r2877 - in jbossxb/branches/1_0/src: test/java/org/jboss/test/xml and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 23 13:49:12 EDT 2008


Author: darran.lofthouse at jboss.com
Date: 2008-06-23 13:49:12 -0400 (Mon, 23 Jun 2008)
New Revision: 2877

Modified:
   jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/SimpleTypeBindings.java
   jbossxb/branches/1_0/src/test/java/org/jboss/test/xml/SimpleTypeBindingUnitTestCase.java
Log:
[JBXB-148] xsd:decimal marshalled in exponential form.

Modified: jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/SimpleTypeBindings.java
===================================================================
--- jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/SimpleTypeBindings.java	2008-06-23 15:39:39 UTC (rev 2876)
+++ jbossxb/branches/1_0/src/main/java/org/jboss/xb/binding/SimpleTypeBindings.java	2008-06-23 17:49:12 UTC (rev 2877)
@@ -29,6 +29,8 @@
 import java.io.ByteArrayOutputStream;
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.net.URISyntaxException;
@@ -271,6 +273,30 @@
       }
    };
 
+   private static final Method BIG_DECIMAL_TO_STRING;
+
+   static
+   {
+      Class bigDecimalClass = BigDecimal.class;
+      Method bigDecimalToString = null;
+      try 
+      {
+         bigDecimalToString = bigDecimalClass.getMethod("toPlainString", new Class[] {});
+      } 
+      catch (NoSuchMethodException e) 
+      {
+         try 
+         {
+            bigDecimalToString = bigDecimalClass.getMethod("toString", new Class[] {});
+         } 
+         catch (NoSuchMethodException e2)
+         {
+        	 throw new JBossXBRuntimeException("Unable to find java.math.BigDecimal.toString() method",e2);
+         }
+      }
+      BIG_DECIMAL_TO_STRING = bigDecimalToString;
+   }
+	
    // check for uniqueness of hashCode's
    static
    {
@@ -1135,7 +1161,14 @@
       else if(typeCode == XS_DECIMAL)
       {
          BigDecimal bd = (BigDecimal)value;
-         result = bd.toString();
+         try 
+         {
+            result = (String) BIG_DECIMAL_TO_STRING.invoke(bd, new Object[] {});
+         }
+         catch (Exception e)
+         {
+            throw new JBossXBRuntimeException("Unable to invoke java.math.BigDecimal." + BIG_DECIMAL_TO_STRING.getName() + "() method.", e);
+         }
       }
       else if(typeCode == XS_DATETIME)
       {

Modified: jbossxb/branches/1_0/src/test/java/org/jboss/test/xml/SimpleTypeBindingUnitTestCase.java
===================================================================
--- jbossxb/branches/1_0/src/test/java/org/jboss/test/xml/SimpleTypeBindingUnitTestCase.java	2008-06-23 15:39:39 UTC (rev 2876)
+++ jbossxb/branches/1_0/src/test/java/org/jboss/test/xml/SimpleTypeBindingUnitTestCase.java	2008-06-23 17:49:12 UTC (rev 2877)
@@ -168,6 +168,14 @@
          SimpleTypeBindings.unmarshal("decimal", "12678967.543233", null)
       );
    }
+   
+   public void testDecimalMarshalling() throws Exception
+   {
+	   assertEquals("-1.23",SimpleTypeBindings.marshal("decimal", new BigDecimal("-1.23"), null));
+	   assertEquals("12678967.543233", SimpleTypeBindings.marshal("decimal", new BigDecimal("12678967.543233"), null));
+	   assertEquals("0.0000000001", SimpleTypeBindings.marshal("decimal", new BigDecimal("0.0000000001"), null));	   
+	   assertEquals("0.000000000001", SimpleTypeBindings.marshal("decimal", new BigDecimal("0.000000000001"), null));
+   }
 
    public void testAnyUriUnmarshalling() throws Exception
    {




More information about the jboss-svn-commits mailing list