Hi Jean-Philippe,

Not obvious, but a quirk of the code generation used with JiBX. The 
handling for collections is unfortunately messy, and in this case trying 
to use style="text" just takes the code generation down a wrong path.

The only way I know to do what you want is by writing a custom 
marshaller/unmarshaller which handles the format you want. You should 
then be able to reference the marshaller and unmarshaller directly on 
the child <structure> element within the <collection>

- Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Gagnon, Jean-Philippe (LTI) wrote:
>
> Hi,
>
> I’m trying to marshall a collection of String in an element with a 
> constant attribute as in this example
>
> Java:
>
> private List<String> myItems = new ArrayList<String>();
>
> XML:
>
> <Item version="V2">item1</Item>
>
> <Item version="V2">item2</Item>
>
> <Item version="V2">item3</Item>
>
> I was expecting this binding to work :
>
> <collection field="myItems" create-type="java.util.ArrayList">
>
> <structure name="Item" >
>
> <value style="attribute" name="version" constant="V2"/>
>
> <value style="text" type="java.lang.String"/>
>
> </structure>
>
> </collection>
>
> But I get this exception from the binding compiler:
>
> Error: <value> elements within a collection must define element name 
> for unmarshalling; on value element at (line 72, col 54, in 
> ./binding/scenarioBinding.xml)
>
> [bind] Error: Type must be specified on outermost <structure> element 
> within collection; on structure element at (line 70, col 32, in 
> ./binding/scenarioBinding.xml)
>
> I have also tried to add the type="java.lang.String" to the structure 
> element but it gives me this exception
>
> [bind] *** Error during code generation for file 
> './binding/scenarioBinding.xml' - please enter a bug report for this 
> error in Jira if the problem is not listed as fixed on the online 
> status page ***
>
> [bind] java.lang.IllegalStateException: Internal error: Expected 
> org.jibx.runtime.impl.MarshallingContext on stack, found java.lang.String
>
> [bind] full stack:
>
> [bind] 0: org.jibx.runtime.impl.MarshallingContext
>
> [bind] 1: java.lang.String
>
> [bind] 2: java.lang.String
>
> [bind] 3: int
>
> [bind] 4: java.lang.String
>
> [bind] 5: java.lang.String
>
> [bind] at 
> org.jibx.binding.classes.MethodBuilder.verifyCompatible(MethodBuilder.java:420)
>
> Am I missing something obvious?
>
> Thank you
>
> JP
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>   

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to