Re: [Simple-support] <field></field> -> ""
Brought to you by:
niallg
|
From: Timo R. <tim...@di...> - 2011-04-15 21:43:25
|
Hello Jake,
> Hello,
> I would like to have the behavior when I see something like:
> <field></field>
> so that it my instance:
> [...]
> is set to an empty string as opposed to null. Can you give me a hint
> on where to look so I can change this behavior?
I don't know if there is a parameter for this in the serializer, but
one solution might be to use the @Commit annotation. From the
tutorial:
"The commit method is invoked in much the same way, the persister
looks for a method marked with the commit annotation, if one exists
it is invoked. However, unlike the validate method the commit method
is typically used to build further data structures, for example hash
tables or trees."
So you could just set your field to an empty string if it is null in
the method annotated with @Commit:
@Commit
public void commit()
{
if ( this.field == null )
this.field = "";
}
Hope that helps - maybe there is a better solution.
Best regards,
Timo
|