You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Christian Mittendorf <ch...@freenet.de> on 2006/09/26 13:03:37 UTC

Why is method encodeProperty(String, Object, boolean) of XMLEncoder private?

Hello!

I would like to serialize properties that are NULL into the xml.

I therefore submit a String "" to the serializer, but in those cases
the type will be set to String instead of Date or whatever type the
property actually is.

It would be helpful if I could configure the encodeProperty method
in a way that it would do something else than simply return if a
value is null:

void encodeProperty(String xmlTag, Object value, boolean useType)
...
if (value == null) {
	return;
}


Christian



Re: Why is method encodeProperty(String, Object, boolean) of XMLEncoder private?

Posted by Christian Mittendorf <ch...@freenet.de>.
Hello!

Am 26.09.2006 um 15:11 schrieb Kevin Menard:

> It looks like the subject and body really ask two different  
> questions.  Addressing the subject, the method is package-protected  
> because in general you should be able to use the public  
> encodeProperty().

I actually changed my mind while writing this email ;-)

But your hint were very helpful and I think I can get the result that  
I wish without the need for changes of cayenne.

I don't need to be compatible with WO, I just want to store an object  
tree as an xml file.

Thanks!

Christian


> With regards to storing null values, I believe it's implemented as  
> is because null indicates a lack of value.  Allowing null was  
> problematic for the serialization process and it was decided that  
> it was better handled in the user's constructor, which should  
> initialize all non-used values to an appropriate null state.  This  
> may have been the WO way of doing things as well (which we were  
> trying to maintain compatibility with).
>
> What is it that you're trying to accomplish?  If it's compelling  
> enough, we can open up a JIRA issue and reinvestigate the matter.
>
> -- 
> Kevin
>
> Christian Mittendorf wrote:
>> Hello!
>>
>> I would like to serialize properties that are NULL into the xml.
>>
>> I therefore submit a String "" to the serializer, but in those cases
>> the type will be set to String instead of Date or whatever type the
>> property actually is.
>>
>> It would be helpful if I could configure the encodeProperty method
>> in a way that it would do something else than simply return if a
>> value is null:
>>
>> void encodeProperty(String xmlTag, Object value, boolean useType)
>> ...
>> if (value == null) {
>>     return;
>> }
>>
>>
>> Christian
>


Re: Why is method encodeProperty(String, Object, boolean) of XMLEncoder private?

Posted by Kevin Menard <km...@servprise.com>.
Hi Christian,

It looks like the subject and body really ask two different questions.  
Addressing the subject, the method is package-protected because in 
general you should be able to use the public encodeProperty().

With regards to storing null values, I believe it's implemented as is 
because null indicates a lack of value.  Allowing null was problematic 
for the serialization process and it was decided that it was better 
handled in the user's constructor, which should initialize all non-used 
values to an appropriate null state.  This may have been the WO way of 
doing things as well (which we were trying to maintain compatibility with).

What is it that you're trying to accomplish?  If it's compelling enough, 
we can open up a JIRA issue and reinvestigate the matter.

-- 
Kevin

Christian Mittendorf wrote:
> Hello!
>
> I would like to serialize properties that are NULL into the xml.
>
> I therefore submit a String "" to the serializer, but in those cases
> the type will be set to String instead of Date or whatever type the
> property actually is.
>
> It would be helpful if I could configure the encodeProperty method
> in a way that it would do something else than simply return if a
> value is null:
>
> void encodeProperty(String xmlTag, Object value, boolean useType)
> ...
> if (value == null) {
>     return;
> }
>
>
> Christian