Thanks for letting me know. I looked into this and found a messier and deeper issue, where optional elements with empty content weren't being properly distinguished from missing elements (http://jira.codehaus.org/secure/ViewIssue.jspa?key=JIBX-9). I've now fixed this in the CVS code, though you may need to wait a day or so before the updates show up in public CVS (sourceforge delay).

You can now do this to get full round-tripping (unmarshalling and marshalling):

   <value name="j" test-method="testJ" get-method="getJ" set-method="setJ"
       usage="optional"/>

private boolean j;
private boolean testJ() {
return j;
}
private String getJ() {
return "";
}
private void setJ(String value) {
j = value != null;
}


If you're only unmarshalling, you should also be able to use the custom deserializer approach. You still need a test-method for marshalling, though.

- Dennis

mark helm wrote:

Both approaches "specify set-method" and "use custom deserializer" did not work in my case.
With both approaches, a null reference was passed to the respective method,
independent of whether the empty tag <ISBLACK/> was present or not.


The approach "specify set-method" in combination with this custom Unmarshaller worked:

<structure name="black" set-method="setBlackString"
 usage="optional" unmarshaller="MyUnmarshaller"/>

public class MyUnmarshaller implements IUnmarshaller, IAliasable {
private String m_uri;
private String m_name;
public MyUnmarshaller(String uri, int index, String name) {
m_uri = uri;
m_name = name;
}
public boolean isPresent(IUnmarshallingContext ctx) throws JiBXException {
return ctx.isAt(m_uri, m_name);
}
public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException {
UnmarshallingContext ctx = (UnmarshallingContext)ictx;
ctx.parsePastEndTag(m_uri, m_name);
return "";
}
}


Quality/correctness: is this MyUnmarshaller code fine or do I disregard some JiBX best practice?

Mark.

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963





-- Dennis M. Sosnoski Enterprise Java, XML, and Web Services Training and Consulting http://www.sosnoski.com Redmond, WA 425.885.7197




------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ jibx-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to