Search code examples
javaxmlbindinggoogle-contacts-apijibx

JIBX binding and Google Contacts with flexible=true


I have a simple binding:

<binding>
    <mapping name="entry" class="google.vo.GoogleContactsEntry" ordered="false">
        <value name="title" field="title" usage="optional" />
        <value name="email" field="email" usage="optional" />   
    </mapping>


    <mapping name="feed" class="google.vo.GoogleContacts" ordered="false" flexible="true">
        <namespace uri="http://www.w3.org/2005/Atom" default="elements"/>
        <value name="id" field="id" usage="optional" />
        <value name="updated" field="updatedString" usage="optional" />
        <value name="title" field="title" usage="optional" />
        <collection item-type="google.vo.GoogleContactsEntry" name="entries" field="entries"/>
    </mapping>
</binding>

The problem is in Collection element, which needs name="entries". Google returns entries without a wrapping element. Just like this:

<feed>

    <entry>

    </entry>

    <entry>

    </entry>

</feed>

And JiBX expects:

<feed>
    <entries>
        <entry>

        </entry>

        <entry>

        </entry>
    <entries>       
</feed>

Without element name in the binding scheme at collection, JiBX doesn't compile. Is there a solution?


Solution

  • Notorious work-A-round:

    resp = StringUtils.replaceOnce(resp, "<entry>", "<entries><entry>");
    resp = StringUtils.replaceOnce(resp, "</feed>", "</entries></feed>");