views:

157

answers:

2

Strange thing...

I have a binding definition user-wrapper.xml:

<binding>
    <include path="core-wrapper.xml" />
    <include path="user-composite-entity.xml" />

    <mapping name="users" class="UserWrapper" extends="CoreWrapper">
     <structure map-as="CoreWrapper" usage="optional" />
     <collection field="users" usage="optional" item-type="UserCompositeEntity">

     </collection>
    </mapping>
</binding>

Next I have this binding definition user-composite-entity.xml (included in upper file):

<binding>
    <include path="core-composite-entity.xml" />
    <include path="user-entity.xml" />

    <mapping name="user" class="UserCompositeEntity" extends="CoreCompositeEntity">
     <structure map-as="CoreCompositeEntity" />
     <structure field="userEntity" usage="optional" />
     <structure field="meta" marshaller="UserMetaHashMapper" unmarshaller="UserMetaHashMapper" usage="optional" />  
    </mapping>
</binding>

Now, if I call REST which uses binding user-wrapper.xml, mapping goes successfully through. If I call REST which uses binding user-composite-entity.xml I get the next error:

org.jibx.runtime.JiBXException: Multiple bindings defined for class UserCompositeEntity

Now the strange thing (for me). If I remove from user-wrapper.xml <include path="user-composite-entity.xml" /> goes a like this: - call with user-composite-entity.xml is a succes, - call with user-wrapper.xml I get the error:

org.jibx.runtime.JiBXException: No marshaller defined for class UserCompositeEntity
A: 

This email thread seems to have some information.

elhoim
I know how to use Google ;) I found out, that JiBX compiles all classes in each binding, so if you have same classes in multiple bindings, JiBX compiles them all. I just needed to move all from user-wrapper.xml to user-composite-entity.xml and it works.
Trick
Maybe take some time to answer with some details and select it as an answer, so that it would be referenced on StackOverflow
elhoim
A: 

How it works now: I don't have user-wrapper.xml anymore and user-composite-entity.xml looks like that:

<binding>
 <include path="core-wrapper.xml" />
 <include path="core-composite-entity.xml" />
 <include path="user-entity.xml" />

 <mapping name="users" class="UserWrapper" extends="CoreWrapper">
  <structure map-as="CoreWrapper" usage="optional" />
  <collection field="users" usage="optional" >   
  </collection>
 </mapping>

 <mapping name="user" class="UserCompositeEntity" extends="CoreCompositeEntity">
  <structure map-as="CoreCompositeEntity" />
  <structure field="userEntity" usage="optional" />
  <structure field="meta" marshaller="UserMetaHashMapper" unmarshaller="UserMetaHashMapper" usage="optional" />  
 </mapping>
</binding>

The problem was, because before I in user-wrapper.xml included user-composite-entity.xml and JiBX compiled it again (for user-wrapper.xml). That's why there were multiple binding definitions...

Trick