Looking at the code (fragments) supplied, I cannot see anything that is
obviously wrong. In other words, we need to have a more detailed look at
this. Can I please ask you to crete a new JIra issue and attach a fully
fledged JUnit test case that highlights the issue. Please do not forget
to attach all relevant files, incl. mapping file, Java classes, etc.
Please have a look at
http://castor.org/how-to-submit-an-xml-bug.html
for guidelines on how to create such a test case.
Regards
Werner
Oisin Boydell wrote:
Hi,
I'm having a problem with the speed of marshalling objects to XML, and
it seems strange to me that when I supply a mapping file to the
marshaller the marshal(Object) method actually takes longer to execute
than when I don't supply a mapping (so it marshals by introspection).
Here is my code with the timing of the .marshal(Object) method:
StringWriter sw = new StringWriter();
Marshaller marshaller = new Marshaller(sw);
marshaller.setMarshalAsDocument(false);
marshaller.setSuppressXSIType (true);
marshaller.setValidation(false);
marshaller.setMapping(mapping);
Date then = new Date();
marshaller.marshal(this);
long ms = new Date().getTime() - then.getTime();
However if I replace " marshaller.marshal(this);" with
"Marshaller.marshal(this, sw);" so it uses introspection instead of the
specified mapping then the method completes way quicker. In fact it
takes up to a second to marshal the object and they are not very large
or complex objects so I suspect something is wrong. I would have thought
that introspection would be slower. I've tried all the techniques such
as caching a ClassDescriptorResolver but the slow execution is actually
when marshalling with the marshal(Object) method and not the loading of
the mapping file etc.
Maybe there is something wrong with the mapping file I'm using? Here is is:
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version
1.0//EN" " http://castor.org/mapping.dtd">
<mapping>
<description>Mapping of CwsResult and associated classes</description>
<class name=" util.result.SelectionData">
<map-to xml="SELECTION_DATA" />
<field name="query" set-method="setQuery" get-method="getQuery"
type="string" >
<bind-xml name="QUERY" node="element" />
</field>
<field name="snippet" set-method="setSnippet"
get-method="getSnippet" type="string">
<bind-xml name="SNIPPET" node="element" />
</field>
<field name="timestamp" set-method="setTimestamp"
get-method="getTimestamp" type="date" >
<bind-xml name="TIMESTAMP" node="attribute" />
</field>
</class>
<class name="util.result.RecommenderSelectionData ">
<map-to xml="RECOMMENDER_SELECTION_DATA" />
<field name="score" set-method="setScore" get-method="getScore"
type="double" >
<bind-xml name="SCORE" node="element" />
</field>
<field name="selections" set-method="setSelections"
get-method="getSelections" type=" util.result.SelectionData"
collection="arraylist">
<bind-xml name="SELECTIONS" node="element" />
</field>
<field name="userId" set-method="setUserId"
get-method="getUserId" type="long" >
<bind-xml name="USERID" node="attribute" />
</field>
</class>
<class name=" util.result.CwsResult">
<map-to xml="RESULT" />
<field name="title" set-method="setTitle" get-method="getTitle"
type="string" >
<bind-xml name="TITLE" node="element" />
</field>
<field name="displaySnippet" set-method="setDisplaySnippet"
get-method="getDisplaySnippet" type="string" >
<bind-xml name="DISPLAY_SNIPPET" node="element" />
</field>
<field name="displayUrl" get-method="getDisplayUrl"
type="string" >
<bind-xml name="DISPLAY_URL" node="element" />
</field>
<field name="url" set-method="setUrl" get-method="getUrl"
type=" java.net.URL" >
<bind-xml name="URL" node="element" />
</field>
<field name="urlHash" set-method="setUrlHash"
get-method="getUrlHash" type="string" >
<bind-xml name="URLHASH" node="attribute" />
</field>
<field name="recommenderSelectionData"
set-method="setRecommenderSelectionData"
get-method="getRecommenderSelectionData" type="
util.result.RecommenderSelectionData" collection="arraylist">
<bind-xml name="RECOMMENDER_SELECTION_DATA" node="element" />
</field>
</class>
</mapping>
I would appreciate any help or suggestions as I'm using the marshalling
for a Web application and the time delay for marshalling 10 or so
objects when generating a Web page is unacceptable (up to 10 seconds).
I've seen Castor being used in the same way for other Web applications
which do not seem to suffer from this speed problem and they are using
Castor in the same way as I am.
Many thanks and looking forward to all replies,
Oisin.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email