Hi,

I have tried adding 'add-method' attribute to the binding file as you suggested. However, I believe that the add-method specified here is the method for the collection. However, the addEmployee method resides in the Person class, not in the collection - in this case, HashSet class. So there is an error when running the binding compiler as follow:

Error: add-method addEmployee not found in class java.util.HashSet for collection element at (line 43, col 5, in Campaign/jibx-binding.xml)

Regards,

Vairoj
Take a look at the "post-set" binding attribute
(http://jibx.sourceforge.net/tutorial/binding-extend.html):

Add this to your binding file:

<mapping name=3D"person" class=3D"com.package.Person" =
post-set=3D"postSet">
  <value name=3D"name" field=3D"name" />
  <collection name=3D"employees" add-method=3D"addEmployee"
item-type=3D"Person" usage=3D"optional" />
</mapping>

And this to Person:
public void postSet( IUnmarshallingContext ctx )
{
  if ( ctx.getStackDepth( ) > 1 )
  {
    setEmployer( ( Person ) ctx.getStackObject( 1 ) );
  }
}

The trick is to get at the unmarshalling context and go up one level in
the stack to the parent (but make sure to check the stack depth as shown
above and make sure that you're dealing with a collection element!).




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to