You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2004/09/26 16:27:58 UTC

DO NOT REPLY [Bug 31425] New: - [Patch] Handle Throwables, Exceptinos and Errors as complex types

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31425>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=31425

[Patch] Handle Throwables, Exceptinos and Errors as complex types

           Summary: [Patch] Handle Throwables, Exceptinos and Errors as
                    complex types
           Product: Commons
           Version: Nightly Builds
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Betwixt
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: cgaffga@triplemind.com


I needed to serialize some exception instances to XML and was surprised that 
betwixt handles them as primitive type (because they are under 'java.lang.'). 

I needed a detailed output for the cause property of the exceptions instead 
just a string representation. So I patched the current version (2004-09-25) of 
betwixt to handle types starting with 'java.lang.' and ending 
with 'Exception', 'Error' or 'Throwable' as complex.

So I get nice XML for ex.getCause():

    <cause>
      <message>a cause</message>
      <stack-trace>
        <step>
          <class-name>com.triplemind.test.TestBetwixt</class-name>
          <file-name>TestBetwixt.java</file-name>
          <line-number>28</line-number>
          <method-name>method</method-name>
        </step>
        <step>
          <class-name>com.triplemind.test.TestBetwixt</class-name>
          <file-name>TestBetwixt.java</file-name>
          <line-number>68</line-number>
          <method-name>main</method-name>
        </step>
      </stack-trace>
      <cause>
        <message>/ by zero</message>
        <stack-trace>
          <class-name>com.triplemind.test.TestBetwixt</class-name>
          <file-name>TestBetwixt.java</file-name>
          <line-number>25</line-number>
          <method-name>method</method-name>
        </stack-trace>
        <stack-trace>
          <class-name>com.triplemind.test.TestBetwixt</class-name>
          <file-name>TestBetwixt.java</file-name>
          <line-number>68</line-number>
          <method-name>main</method-name>
        </stack-trace>
      </cause>
    </cause>

I hope this functionality is of general interest and will find it's way into 
the next release of betwixt.

you can find the pathc at the bottom of this message.

regards,
Christoph Gaffga
cgaffga@triplemind.com

Index: TypeBindingStrategy.java
===================================================================
RCS file: /home/cvspublic/jakarta-
commons/betwixt/src/java/org/apache/commons/betwixt/strategy/TypeBindingStrateg
y.java,v
retrieving revision 1.1
diff -u -r1.1 TypeBindingStrategy.java
--- TypeBindingStrategy.java	14 Jul 2004 21:37:54 -0000	1.1
+++ TypeBindingStrategy.java	26 Sep 2004 14:14:53 -0000
@@ -152,6 +152,12 @@
                 
             } else if ( type.equals( Object.class ) ) {
                 return false;
+            } else if ( type.getName().startsWith( "java.lang." )
+                    && ( type.getName().endsWith( "Exception" ) 
+                            || type.getName().endsWith( "Error" ) 
+                            || type.getName().endsWith( "Throwable" ) 
+                    ) ) {
+                return false;
             }
             return type.getName().startsWith( "java.lang." )
                 || Number.class.isAssignableFrom( type )

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org