We ran in to a similar problem where we had to set a boolean depending
on whether the element was present or not. To do so, we used a custom
serializer (included below), with the following <value> element:

<value name='confirmed'
       usage='optional'
       test-method='isValuePresent'
       get-method='isValuePresent'
       set-method='setvaluePresent'
       serializer='EmptyElementSerializer.serialize'
       deserializer='EmptyElementSerializer.deserialize' />


public final class EmptyElementSerializer
{
  private static final String EMPTY_STRING = "";


  private EmptyElementSerializer()
  {
  }

  public static String serialize(boolean b)
  {
    return b ? EMPTY_STRING : null;
  }

  public static boolean deserialize(String val)
  {
    return val != null &&
           ((val.length() == 0) || Boolean.parseBoolean(val));
  }
}

Cheers,
Alex

Paul Mahoney wrote:
> Hi
>  
> I have the following binding:
> 
> <mapping name="OTA_PingRS" class="uk.co.xact.ota.OTA_PingRS">
>     <value name="EchoToken" field="echoToken" usage="optional"/>
>     <value name="TimeStamp" field="timeStamp" usage="optional"/>
>     <value name="Target" field="target" 
> deserializer="uk.co.xact.ota.commonType.Target.get" usage="optional"/>
>     <value name="Version" field="version"/>
>     <value name="TransactionIdentifier" field="transactionIdentifier" 
> usage="optional"/>
>     <value name="SequenceNmbr" field="sequenceNmbr" usage="optional"/>
>     <value name="TransactionStatusCode" field="transactionStatusCode" 
> deserializer="uk.co.xact.ota.commonType.TransactionStatusCode.get" 
> usage="optional"/>
>     <value name="RetransmissionIndicator" field="retransmissionIndicator" 
> usage="optional"/>
>     <value name="PrimaryLangID" field="primaryLangID" usage="optional"/>
>     <value name="AltLangID" field="altLangID" usage="optional"/>
>     <structure ordered="false" choice="true">
>         <structure name="Errors" field="errors" usage="optional"/>
>         <structure usage="optional">
>             <structure name="Success" field="success" usage="optional"/>
>             <structure name="Warnings" field="warnings" usage="optional"/>
>             <value name="EchoData" field="echoData" style="element" 
> usage="optional"/>
>         </structure>
>     </structure>
> </mapping>
> 
> When jibx (1.1.5) unmarshals the message:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <OTA_PingRS xmlns="http://www.opentravel.org/OTA/2003/05"; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05
> OTA_PingRS.xsd" TimeStamp="2003-03-17T11:09:49-05:00" Target="Production" 
> Version="1.001" SequenceNmbr="1">
>     <Success/>
>     <EchoData>Are you There</EchoData>
> </OTA_PingRS>
> 
> The object for the <Success/> element is not created, so if I
> immediately marshal the object tree I get:
> 
> <OTA_PingRS xmlns="http://www.opentravel.org/OTA/2003/05"; 
> TimeStamp="2003-03-17T11:09:49-05:00" Target="Production" Version="1.001" 
> SequenceNmbr="1">
>     <EchoData>Are you There</EchoData>
> </OTA_PingRS>
> 
> As you can see, the <Success/> element is missing.
>  
> Is there a way to tell the unmarshaller to create the object mapped to
> the <Success/> element? Obviously I don't want it if the element is not
> in the XML, but I do if it is... even though it's empty.
>  
> Regards
> Paul
> *----*
> *Paul Mahoney, Director, X-Act Solutions Limited*
> *smail: 71 South Cliff, Bexhill-on-Sea, East Sussex, TN39 3EE*
> *phone: +44 (0) 1424 731240*
> *email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>  
> 
> 
> ------------------------------------------------------------------------
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to