I'm seeing some rather strange behavior in JiBX with regards to abstract
mappings, post-set and its ilk, and the '<structure map-as="foo"/>'
construct.  The oddness isn't described in the docs, so I figure I'll check
on the list to see if it's a bug or just a surprise.  In short, post-set is
sometimes called, and sometimes not..  An example:

Class: 

public class TestClass
{
    public String one;
    public String two;
    public String three;
    
    public void postSet()
    {
        three="three";
    }
    
    public static void main(String args[]) throws Exception
    {
        String testString = "<TestClass></TestClass>";
        IBindingFactory factory = BindingDirectory.getFactory(TestClass.class);
        IUnmarshallingContext c = factory.createUnmarshallingContext();
        TestClass tc = (TestClass) c.unmarshalDocument(new 
StringReader(testString));
        System.out.println(tc.three);
    }
}

Binding:

<binding >
    <mapping class="TestClass" abstract="true" type-name="level-one" >
        <value name="one" field="one" usage="optional"/>
    </mapping>
    
    <mapping class="TestClass" abstract="false" post-set="postSet" 
name="TestClass">
        <structure map-as="level-one"/>
        <value name="two" field="two" usage="optional"/>
    </mapping>
</binding>

In this case, the post-set method is called - the output will be "three".

That's good, I suppose... but...  let's mix it up a little.

Remove the 'two' value element from the second mapping and run the example
again.  Result?  The postSet method is _not_ called, and 'three' remains
null.

Of course, we can always just move the post-set attribute up to the abstract
mapping, and it gets called, once again.  Not that this helps, if my entire
reason for creating a concrete base mapping is to use a post-set that wouldn't
be used against the abstract class.  Joy?

So.. it appears that the concrete mapping only calls its own post-set if
there's something other than a 'map-as' present for mapping?

I admit I'm not entirely sure just what's going on here.  I can recognize
it, and I can see a(n ugly) way to work around it, but...Is this a bug, or
just something I should know to watch for?

-- 
The cake is a lie!


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to