Hi Dennis

I have tried adding a "add-method" to my binding and during binding compilation I receive the following error:

Error: add-method add_JiBX not found in class java.util.Collection; on collection element at (line 38, col 99, in binding.xml)
Error running binding compiler
org.jibx.runtime.JiBXException: Binding binding.xml is unusable because of validation errors
   at org.jibx.binding.Utility.loadBinding(Utility.java:341)
   at org.jibx.binding.Utility.loadFileBinding(Utility.java:408)
   at org.jibx.binding.Compile.compile(Compile.java:296)
   at org.jibx.binding.Compile.main(Compile.java:385)

Which is entirely correct, "add_JiBx" is not on the java.util.Collection class.

Here is my binding:
   <mapping name="BPDs" class="net.xxxx.BPDList">
<collection field="items" add-method="add_JiBX" item-type="net.xxxx.BPD" />
   </mapping>

The current argument of the add-method is Object, originally I had the argument of the add-method of type BPD but that me the same error.

If you have any suggestion or pointers on how the resolve this issue I would be extremely grateful.

Cheers

Jon

Dennis Sosnoski
Mon, 08 Sep 2008 02:34:17 -0700

Hi Jon,

There's one way I can think of to get the behavior you want, but it's not automatic - mostly because what you want is a very unusual sort of behavior, effectively merging data values from the XML document into existing structures.

What you can do is to build on the "default" behavior of JiBX by using an add method for the collection of sub-objects. In that add method, rather than just adding the supplied object to the collection you could first check for an existing instance of the sub-object, and if found you could do an update which would copy all non-null fields of the unmarshalled sub-object across to the existing instance. That way you'd update any values which were specified in the XML, while keeping everything else unmodified.

You could also write a custom unmarshaller, which would look at the element representing the sub-object and check for an existing instance. If an existing instance was found you could gen pass that on to JiBX for the actual unmarshalling. However, this approach would mean that values which were not specified in the XML would be overwritten with their default values (null in the case of object references), which doesn't sound like what you want.

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz



Jon Little wrote:
> Hey People
>
> Am still having trouble resolving the below issue.
>
> Does anyone have any advice or pointers at all?
>
> Cheers for your help
>
> Jon
>
> Jon Little wrote:
>> Hi
>>
>> I have an object structure where the root object contains several >> collections of sub-objects.
>>
>> The operation that we do most often is given an existing object, the >> incoming XML alters/updates attributes of the root or sub-objects in >> one of the contained collections.
>>
>> This is done by calling ((IUnmarshallable) target).unmarshal(umc); >> where target is the existing and instantiation root object.
>>
>> If the XML updates attributes of the root then there are no issues.
>>
>> If the XML update adds new objects the one of the collections then >> there are no issues.
>>
>> If the XML updates attributes of a sub-object in one of the contained >> collections then this is were problems begin. Upon unmarshalling Jibx >> creates a new object which is then added to the appropriate >> collection. _Rather_ than updating the existing sub-object in the >> appropriate collection.
>>
>> Can anyone point me in the right direction for resolving this issue?
>>
>> Thanks
>>
>> Jon
>>
>>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> 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=/ 
<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=/ 
<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