null values

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

null values

falcorn
Hi.
Can I be shure that if xml doesn't contains one some tag,
then java fields will be null;
i.e.
Class c{
String a1;
String a2;
}
<xml>
<a1>dd</a1>
</xml>

Do a2 will be null?
What if there will be empty tag (<a2/>)?
Greetings
Piotr Idzikowski

----------------------------------------------------------------------
Poznaj Stefana! Zmien komunikator! >>> http://link.interia.pl/f1924

Reply | Threaded
Open this post in threaded view
|

RE: null values

Jörg Schaible
Piotr Idzikowski wrote on Tuesday, April 18, 2006 1:32 PM:

> Hi.
> Can I be shure that if xml doesn't contains one some tag,
> then java fields will be null;
> i.e.
> Class c{
> String a1;
> String a2;
> }
> <xml>
> <a1>dd</a1>
> </xml>
>
> Do a2 will be null?

Yes. This behaviour is currently hard-coded, although we might make it configurable at some time.

> What if there will be empty tag (<a2/>)?

Officially it is simply undefined, but depends actually on the field type. The value of the tag is the empty string and it depends on the field converter if this empty string can be converted into a proper value of the necessary type. In case of a2 being an int, XStream will throw an exception.

- Jörg
Reply | Threaded
Open this post in threaded view
|

Re: null values

João Kreuzberg
Hi...
 
how can I ignore a Class to be converted
on XStream?
 
greettings
 
João
Reply | Threaded
Open this post in threaded view
|

Re: null values

Jörg Schaible-2
João Kreuzberg wrote:

> Hi...
>
> how can I ignore a Class to be converted
> on XStream?
>
> greettings
>
> João


Set the member to transient or try xstream.omitField.

- Jörg

Reply | Threaded
Open this post in threaded view
|

Re: Re: null values

João Kreuzberg
I'm sorry...
 
But I would like to
ignore a entire class
 
and XStream.omitField() ignores only
a field....
 
i didn't understand about the member to transient...
 
thanks
 
João

 
On 5/2/06, Jörg Schaible <[hidden email]> wrote:
João Kreuzberg wrote:

> Hi...
>
> how can I ignore a Class to be converted
> on XStream?
>
> greettings
>
> João


Set the member to transient or try xstream.omitField.

- Jörg




--
João Kreuzberg
Reply | Threaded
Open this post in threaded view
|

Re: Re: null values

guilherme_silveira
Set every member variable of this class type to transient.

You might also implement your own converter for this class...

Guilherme

On 5/2/06, João Kreuzberg <[hidden email]> wrote:

>
> I'm sorry...
>
> But I would like to
> ignore a entire class
>
> and XStream.omitField() ignores only
> a field....
>
> i didn't understand about the member to transient...
>
> thanks
>
> João
>
>
> On 5/2/06, Jörg Schaible <[hidden email]> wrote:
> > João Kreuzberg wrote:
> >
> > > Hi...
> > >
> > > how can I ignore a Class to be converted
> > > on XStream?
> > >
> > > greettings
> > >
> > > João
> >
> >
> > Set the member to transient or try xstream.omitField.
> >
> > - Jörg
> >
> >
>
>
>
> --
> João Kreuzberg


--
Guilherme Silveira
--------------------------------------------------
[hidden email]
Caelum - Ensino e Solucoes em Java
www.caelum.com.br
Reply | Threaded
Open this post in threaded view
|

Re: Re: null values

Jörg Schaible-2
In reply to this post by João Kreuzberg
Hi João,

João Kreuzberg wrote:

> I'm sorry...
>
> But I would like to
> ignore a entire class
>
> and XStream.omitField() ignores only
> a field....
>
> i didn't understand about the member to transient...

You can set a class member to transient.

It is as Guilherme already told you, xstream.omitField as well as transient
work on the field level. There's no functionality to exclude by type. You
might write a CustomConverter, that does nothing for certain types though,
but this is a one way operation, you will not be able to unmarshal your
object from the generated XML again.

- Jörg