Here is the original post that Dennis replied to over a year ago:
*
Your binding says that the <features> collections consists only of
<option> elements:

<collection name="features" field="features" usage="optional"
create-type="java.util.HashSet">
<structure name="option"
marshaller="com.edmunds.vehicle.jibx.VdmIdRefMapper"
    unmarshaller="com.edmunds.vehicle.jibx.VdmIdRefMapper"/>
</collection>

so when a different element start tag is found (<color>) you get an
exception. If you want to mix several different types of child elements
in the collections you're best off adding a <structure> definition for
each one, with a specific type="..." to show which Java type matches up
with each child element. If you do this, you'll probably also want to
add ordered="false" on the <collection> element, so that the child
elements can be in any order.

I think you could also make your VdmIdRefMapper handle the element names
for the items in the collection directly, and remove the name="option"
attribute from the <structure> definition. I won't guarantee this will
work properly (there are a lot of issues around the code generation not
knowing what element name to expect), but I think the current code
allows it. In this case you'd only have the single <structure> within
the <collection>, since the mapper would handle the element names as
appropriate to the actual object types.

Since you've got the same collection information appearing in two
different places you may want to use an abstract <mapping> for
java.util.Set so you only define the <collection> details in one place.
You can then reference that abstract mapping where needed (replacing the
<collection name="features" ...> elements in the current binding with
<struct name="features" ... map-as="setAbstractMapping">, for instance).

- Dennis*

On Fri, May 29, 2009 at 11:01 AM, aidano <aida...@yahoo.com> wrote:
>
> We marshall the following type of XML where Option, Color and UsedFeature
all
> extend a Feature class:
>
> <features>
>  <option>
>    <feature ..
>  </option>
>  <option>
>    <feature ..
>  </option
>  <color>
>    <feature ..
>  </color>
>  <color>
>    <feature ..
>  </color>
>  <usedFeature>
>    <feature...
>  </usedFeature>
> </features>
>
>
> The following bindings XML is used to define a  Set of Features belonging
to
> another object. Any one of option, color or usedFeature can occur any
number
> of times:
>
> <mapping ns="http://www.edmunds.com/esbservices/schemas";
> class="com.edmunds.vehicle.coherence.ModelYearImpl"
>             name="modelYear" post-set="postset">
> ...
>        <structure name="features" field="features" usage="optional"
> map-as="features-set"/>
> ....
>    </mapping>
>
>
>    <mapping abstract="true" type-name="features-set" class="java.util.Set"
> create-type="java.util.HashSet">
>        <collection ordered="false">
>            <structure name="option"
> type="com.edmunds.vehicle.coherence.OptionImpl"
>
> marshaller="com.edmunds.vehicle.util.jibx.FeatureIdRefMapper"
>
> unmarshaller="com.edmunds.vehicle.util.jibx.FeatureIdRefMapper"/>
>            <structure name="color"
> type="com.edmunds.vehicle.coherence.ColorImpl"
>
> marshaller="com.edmunds.vehicle.util.jibx.FeatureIdRefMapper"
>
> unmarshaller="com.edmunds.vehicle.util.jibx.FeatureIdRefMapper"/>
>            <structure name="usedFeature"
> type="com.edmunds.vehicle.coherence.UsedFeatureImpl"
>
> marshaller="com.edmunds.vehicle.util.jibx.FeatureIdRefMapper"
>
> unmarshaller="com.edmunds.vehicle.util.jibx.FeatureIdRefMapper"/>
>        </collection>
>    </mapping>
>
>
>
>
> This all worked fine with Jibx 1.1.5, but with 1.2.1 I get an error
> informing me that it was expecting all of the elements to be of the same
> type (option OR color OR usedFeature), i.e.
>
> java.lang.RuntimeException: org.jibx.runtime.JiBXException: Expected
> "{http://www.edmunds.com/esbservices/schemas}features"; end tag, found
> "{http://www.edmunds.com/esbservices/schemas}color"; start tag (line 1, col
> 75244)
>        at
>
com.edmunds.vehicle.end2end.VehicleEndToEndTest.saveMakeTree(VehicleEndToEndTest.java:135)
> Caused by: org.jibx.runtime.JiBXException: Expected
> "{http://www.edmunds.com/esbservices/schemas}features"; end tag, found
> "{http://www.edmunds.com/esbservices/schemas}color"; start tag (line 1, col
> 75244)
>        at
>
org.jibx.runtime.impl.UnmarshallingContext.parsePastCurrentEndTag(UnmarshallingContext.java:736)
>
>
>
> Is there some new attribute or something that I need to get this to work
> with 1.2.1?
> --
> View this message in context:
http://www.nabble.com/Issue-with-binding-file-after-upgrading-from-1.1.5--%3E-1.2.1-tp23784598p23784598.html
> Sent from the jibx-users mailing list archive at Nabble.com.
>
>
>
------------------------------------------------------------------------------
> Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
> is a gathering of tech-side developers & brand creativity professionals.
Meet
> the minds behind Google Creative Lab, Visual Complexity, Processing, &
> iPhoneDevCamp as they present alongside digital heavyweights like
Barbarian
> Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to