I'm having an issue mapping a collection whose items are interfaces. For
example, I've got a Customer that has an interface IOrder as an attribute.
IOrder contains a List which will contain IOrderItem interfaces. If I map
the collection using a nested structure, everything works fine.
<mapping class="IOrder" name="order" abstract="true" factory="
Order.getInstance" >
<value name="order-number" get-method="getOrderNumber"
set-method="setOrderNumber" />
<collection name="order-items" create-type="java.util.ArrayList"
get-method="getItems" set-method="setItems">
<!-- Define IOrderItem -->
<structure name="order-item" type="IOrderItem"
abstract="true" factory="OrderItem.getInstance">
<value name="item-number" get-method="getItemNumber"
set-method="setItemNumber" />
</structure>
</collection>
While this works, it seems more appropriate to define IOrderItem in its own
mapping so that I can reuse that definition instead of redefining the
structure for every class that uses it. I found a post in the mailing list
archive that suggested something like this.
<mapping class="IOrder" name="order" abstract="true" factory="
Order.getInstance" >
<value name="order-number" get-method="getOrderNumber"
set-method="setOrderNumber" />
<collection name="order-items" create-type="java.util.ArrayList"
get-method="getItems" set-method="setItems">
<structure name="order-item" type="IOrderItem" />
</collection>
</mapping>
<!-- Define IOrderItem -->
<mapping name="order-item" class="IOrderItem"
abstract="true" factory=" OrderItem.getInstance">
<value name="item-number" get-method="getItemNumber"
set-method="setItemNumber" />
</mapping>
When I do this, I get the following error.
The java class could not be loaded. java.lang.ClassFormatError: (IOrderItem)
interface method must be public and abstract at offset=265
I've also tried defining the collection more generically...
<mapping class="IOrder" name="order" abstract="true" factory="
Order.getInstance" >
<value name="order-number" get-method="getOrderNumber"
set-method="setOrderNumber" />
<collection name="order-items" create-type="java.util.ArrayList"
get-method="getItems" set-method="setItems" />
</mapping>
Which gives this exception...
java.lang.ClassCastException: OrderItem incompatible with
org.jibx.runtime.IMarshallable
at JiBX_MungeAdapter.JiBX_binding_mapping_marshal_1_2()
at JiBX_MungeAdapter.JiBX_binding_mapping_marshal_1_3()
at Customer.JiBX_binding_mapping_marshal_1_0(Customer.java)
at JiBX_binding_mappingCustomer_access.marshal()
at Customer.marshal(Customer.java)
at org.jibx.runtime.impl.MarshallingContext.marshalRoot (
MarshallingContext.java:1044)
at org.jibx.runtime.impl.MarshallingContext.marshalDocument(
MarshallingContext.java:1114)
at TestHarness.main(TestHarness.java:32)
The mapping does work if I use the concrete class instead of the interface!
This is the first time I've used Jibx so I'm not sure if I'm just missing an
option on one of the mapping elements that will make this magically work or
if I really just need to either use the implementation class or duplicate
the structure when I need to.
Any insight would be much appreciated! I can provide the full interface,
implementation, and binding if it would help.
Zach Paul
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users