Re: [Simple-support] Element/Attribute Default Values
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2007-06-11 21:38:59
|
Hi,
Yes there is a way to intercept, for example:
public class MyExample {
private static final DEFAULT_VALUE = "[[NULL]]";
@Element
private String webAddress
@Commit
private void resolveMyDefault() {
if(webAddress.equals(DEFAULT_VALUE)) {
webAddress = null;
}
}
@Persist
private void fixMyObject() {
if(webAddress == null){
webAddress = DEFAULT_VALUE:
}
}
@Complete
private void backToNormal() {
resolveMyDefault();
}
}
This should do the trick, as @Persist gets called just before the object is persisted, and @Complete gets called when its been serialized to the XML document. The @Commit gets called after deserialization so the object values will be reverted to a proper working runtime value.
Hope this helps.
Niall
----- Original Message ----
From: Keith Byrne <ka...@gm...>
To: sim...@li...
Sent: Monday, June 11, 2007 10:33:16 AM
Subject: [Simple-support] Element/Attribute Default Values
I have a situation where a field isn't required, but when it's null and is serialized, the tag still needs to show up empty. Specifically, there is a String field (webAddress) that has an Attribute annotation, that went it's null should be serialized to <webAddress/>, instead of not showing up. Is there a way to intercept the serializing of an Element/Attribute, and based upon it's type, serialize a default value?
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
____________________________________________________________________________________
Sick sense of humor? Visit Yahoo! TV's
Comedy with an Edge to see what's on, when.
http://tv.yahoo.com/collections/222 |