Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

[castor-user] Castor XML 1.3.1 marshals null Collections

Marc Eyrignoux

2013-01-23

Replies: Find Java Web Hosting

Author LoginPost Reply

Up to now my project used an old version of Castor, like 0.9+, and I am working on a migration to the latest release, ie. 1.3.2 or 1.3.3-RC1.

 

I am facing two problems:

 

-          My project runs with a JDK 5, and the releases of Castor 1.3.2 and Castor 1.3.3-RC1 seem to have been built with a JDK 6.

Therefore I get errors at runtime, and I had to switch to Castor 1.3.1, which does not have this problem.

Anyway, I can live with that, it doesn’t matter much, even if the documentation of Castor states that any version should run properly with a JDK 5.

 

-          My true problem is about null Collections: they were NOT marshaled with my old version of Castor.

Now they are, which causes some regressions in my application. I searched everywhere if there a configuration or a property about that, but didn’t find anything.

Is there something to configure somewhere or do I have to correct the regressions one by one ?

 

In order that everything would be clear, here is an example of my problem :

 

I want to marshal the following bean:

 

Public class toto {

               Private Collection myCollection = null;

Private String myString = “test”;

 

Public Collection getMyCollection() { return myCollection; }

Public void setMyCollection( Collection p_collection ) { myCollection = p_collection; }

Public String getMyString() { return myString; }

Public void setMyString( String p_string ) { myString = p_string; }

}

 

If “myString” contains “test” and “myCollection” contains null, my old version didn’t put the collection in the XML result:

<toto>

                <myString>test</myString>

</toto>

 

But now it does :

<toto>

                <myString>test</myString>

                <myCollection/>

</toto>

 

How to tell Castor 1.3+ not to put “<myCollection/>” in the XML stream ?

 

Thanks for your help,

Marc

©2008 junlu.com - Jax Systems, LLC, U.S.A.