Hello there,
If I remember correctly, didn't you say that you are using
Castor for marshaling but NOT for unmarshaling (or vice-versa)?
Try to change your code and do like this:
VehicleReference obj = new VehicleReference();
// set your data
StringWriter writer = new StringWriter();
Marshaller marshaller = new Marshaller(writer);
marshaller.setSuppressXSIType(true);
marshaller.setValidation(true);
marshaller.setDebug(true);
marshaller.marshal(object); // <<<<< this line changes the object
String vehicleString = writer.GETBUFFER().toString();
// then use Castor Unmarshaller to get it
VehicleReference vehicle2 = (VehicleReference)unmarshaller.unmarshal(
new InputSource(new
StringReader(vehicleString)));
and tell me what you got
any particular reason of why you are not using castor for unmarshalling?
Regards
Marco
-----Original Message-----
From: Velusamy Velu [mailto:[EMAIL PROTECTED]
Sent: 04 November 2004 20:25
To: [EMAIL PROTECTED]
Subject: Re: [castor-user] Marshaling issue
Keith:
I agree with you and I am also extremely confident that the Castor
Marshaled does not change any values. So far I have tried every thing
that I could do to find root cause of the problem. The code has been
minimalized just to isolate the problem.
However, there is one more thing I could do. I should do a testing
outside the Eclipse/Tomcat environment. My greatest suspicion is that
the Tomcat caches the object and retrieves it while marshaling. I am
not sure how and why though.
I greatly appreciate your help. You have contributed a wonderful
framework for the Java community.
Thanks
Velusamy K. Velu
(614) 728-0017
>>> [EMAIL PROTECTED] 11/04/04 03:09PM >>>
Well, since I'm extremely confident that the Castor Marshaller doesn't
change any values, and only calls gettter methods or
FieldHandler.getValue(), then it sounds to me like your object is being
controlled by some sort of proxy and when Castor Marshaller invokes a
getter perhaps some sort of Lazy loading is taking place from the
Database.
--Keith
Velusamy Velu wrote:
> Yes, I did. The code snippet was in my original posting. I am
including it here again for the folks out there -
> try
> {
> Marshaller marshaller = new Marshaller(writer);
> marshaller.setSuppressXSIType(true);
> marshaller.setValidation(true);
> marshaller.setDebug(true);
>
> marshaller.marshal(object); // <<<<< this line changes
the object
> writer.flush();
> marshaller = null;
> document = convert(writer.toString());
> }
> catch (Exception e)
> {
> Logger.throwing(e);
> throw new AppException("Unable to create XML: " +
e.getMessage(), e);
> }
> finally
> {
> try
> {
> writer.close();
> }
> catch (IOException e)
> {
> Logger.throwing(e);
> throw new AppException("Error closing the output
stream");
> }
> }
>
> The line of code that changes the values of the attributes of the
object is marshaller.marshal(object);
>
> Please let me know if this is sufficient to resolve the issue.
>
> Thanks
>
> Velusamy K. Velu
> (614) 728-0017
>
>
>>>>[EMAIL PROTECTED] 11/02/04 11:16PM >>>
>
>
>
> Have you tried to simply create a new Marshaller before marshalling?
>
> --Keith
>
> Velusamy Velu wrote:
>
>>Well, I am not even saving the old XML in a file. It is used by STxx
and thrown away. I also followed the suggestion made by Tim. Tim
suggested that I close the stream to which the XML string was written.
The problem still occurs.
>>
>>The source of the problem appears to be the marshaling process
changing the state of the object it marshals. Or, inside the
marshal(object) method an old, stale, cached version of the object is
used. To my amazement I am not sure where, how, when, and which process
does the caching. If I know that I will turn off the caching. Without
knowing that specific information it is not possible to solve this
problem.
>>
>> Below is the expected XML --
>>
>><vehicle-reference index="0">
>> <statuses index="0">
>> <item>AVAILABLE</item>
>> <value>5</value>
>> </statuses>
>> <statuses index="1">
>> <item>INUSE</item>
>> <value>4</value>
>> <selected>YES</selected>
>> </statuses>
>> <statuses index="2">
>> <item>OUTFORMAINTENANCE</item>
>> <value>6</value>
>> </statuses>
>> <statuses index="3">
>> <item>SALVAGED</item>
>> <value>7</value>
>> </statuses>
>></vehicle-reference>
>>
>>However, I get -
>>
>><vehicle-reference index="0">
>> <locations index="0">
>> <item>CDO </item>
>> </locations>
>> <locations index="1">
>> <item>CO </item>
>> </locations>
>>
>> <types index="0">
>> <item>VAN</item>
>> </types>
>> <types index="0">
>> <item>SUV</item>
>> </types>
>>
>> <statuses index="0">
>> <item>AVAILABLE</item>
>> <value>5</value>
>> </statuses>
>> <statuses index="1">
>> <item>INUSE</item>
>> <value>4</value>
>> </statuses>
>> <statuses index="2">
>> <item>OUTFORMAINTENANCE</item>
>> <value>6</value>
>> </statuses>
>> <statuses index="3">
>> <item>SALVAGED</item>
>> <value>7</value>
>> </statuses>
>>
>> <models index="0">
>> <item>ASTRO</item>
>> </models>
>> <models index="0">
>> <item>C-2500</item>
>> </models>
>>
>> <makes index="0">
>> <item>CHEV</item>
>> </makes>
>> <makes index="0">
>> <item>FORD</item>
>> </makes>
>></vehicle-reference>
>>
>>that's wrong.
>>
>>
>>Thanks
>>
>>Velusamy K. Velu
>>(614) 728-0017
>>
>>
>>
>>>>>[EMAIL PROTECTED] 11/02/04 12:27PM >>>
>>
>>
>>I haven't used the xml side of castor greatly, but have you tried
>>deleting the old xml file, and then marshaling the object again? I
>>know its kinda a shot in the dark, but since you said the first
>>marshal worked fine its worth a shot.
>>
>>
>>On Tue, 02 Nov 2004 11:07:46 -0500, Velusamy Velu
>><[EMAIL PROTECTED]> wrote:
>>
>>
>>>Hello:
>>>
>>>I am continuing to investigate this problem and found the following
additional information -
>>>
>>>The type of the object to be marshaled is VehicleReference
>>> public class VehicleReference extends Selectable
>>> {
>>> private ArrayList types = null;
>>> private ArrayList models = null;
>>> private ArrayList makes = null;
>>> private DropdownList statuses = null;
>>> private DropdownList locations = null;
>>> private String license = null;
>>> ...
>>> }
>>>To isolate and repeat the problem only the statuses is populated.
All other attributes left in null state. The statuses is of type
DropdownList which extends the java.util.ArrayList and adds a couple of
more functionalities.
>>>
>>>In debug mode while stepping through the code the object (an instance
of VehicleReference) is good until the marshaller.marshall(object)
method is called.
>>>
>>>state of the object before calling -
>>> public class VehicleReference extends Selectable
>>> {
>>> private ArrayList types = null;
>>> private ArrayList models = null;
>>> private ArrayList makes = null;
>>> private DropdownList statuses = DropdowList (id=305)
>>> private DropdownList locations = null;
>>> private String license = null;
>>> ...
>>> }
>>>
>>>state of the object after that call
>>> public class VehicleReference extends Selectable
>>> {
>>> private ArrayList types = DropdowList (id=306)
>>> private ArrayList models = DropdowList (id=304)
>>> private ArrayList makes = DropdowList (id=303)
>>> private DropdownList statuses = DropdowList (id=305)
>>> private DropdownList locations = DropdowList (id=302)
>>> private String license = null;
>>> ...
>>> }
>>>
>>>The values assigned during the marshaling process to types, models,
makes, and locations are all from a previous run (about 3 days old) of
the program. All of those values are accurate values but not wanted
now.
>>>
>>>The result of this is the XML produced is incorrect.
>>>
>>>I could see that the old object has been cached. But by which
process? and why it does not refresh? and why it overrides the current
state of the object? Why this happens only with the objects that are in
collections (ArrayList or Vector)?
>>>
>>>Your help would be greatly appreciated.
>>>
>>>My previous email is truncated in the interest of keeping this thread
relatively clean.
>>>
>>>
>>>Thanks
>>>
>>>Velusamy K. Velu
>>>(614) 728-0017
>>>
>>>
>>>
>>>>>>[EMAIL PROTECTED] 11/02/04 08:46AM >>>
>>>
>>>Hello:
>>>
>>>We are a developing a J2EE based web application. The combination of
Struts and STxx is used to
>>>.
>>>.
>>>
>>>
>>>.
>>>
>>>I wonder if anyone ran into this kind of problem. Any pointers would
greatly help us. We have been spending about 4 days fruitlessly on this
problem. I can provide more code snippets if necessary.
>>>
>>>Thanks
>>>
>>>Velusamy K. Velu
>>>(614) 728-0017
>>>
>>>
>>>-----------------------------------------------------------
>>>If you wish to unsubscribe from this mailing, send mail to
>>>[EMAIL PROTECTED] with a subject of:
>>> unsubscribe castor-user
>>>
>>>
>>>
>>
>>
>>
>>
>>-----------------------------------------------------------
>>If you wish to unsubscribe from this mailing, send mail to
>>[EMAIL PROTECTED] with a subject of:
>> unsubscribe castor-user
>>
>>
>>
>>----------------------------------------------------------------------
--
>>
>>-----------------------------------------------------------
>>If you wish to unsubscribe from this mailing, send mail to
>>[EMAIL PROTECTED] with a subject of:
>> unsubscribe castor-user
>
>
>
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-user
>
>
>
>
------------------------------------------------------------------------
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-user
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user