Re: [Simple-support] <field></field> -> ""
Brought to you by:
niallg
|
From: Jouni L. <Jou...@sa...> - 2011-04-18 06:40:52
|
Or you might want to try registering a custom converter for String that does null -> empty string conversion
public class SimpleXMLStringConverter implements Converter<String> {
@Override
public String read(InputNode node) throws Exception {
String value = node.getValue();
if(value == null) {
value = "";
}
return value;
}
@Override
public void write(OutputNode node, String value) throws Exception {
node.setValue(value);
}
}
Just register that to a single element with the @Convert annotation or for global functionality to the Persister.
Regards,
Jouni
On 16.4.11 00:18, "Timo Rumland" <tim...@di...> wrote:
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
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|