Hi Lars,
This should actually be flagged as an error in the binding definition,
since there's no way for JiBX to handle it correctly. The problem is
that you have a collection made up of an arbitrary number of <b>
elements. The only way to tell when you've reached the end of the
collection is by finding an element that's *not* a <b> (the <name>
element in the case of your binding). But by the time you reach the
<name> element you will have skipped past the text you wanted to save.
I'll see about fixing the binding validation code to catch this. If you
want a structure of this type you can make it workable by adding an
element name for the collection; that way the end tag for that
collection element shows when to look for text content.
- Dennis
Lars Braubach wrote:
Hi,
I encountered a serious unmarshalling bug when using
collections together with a value that has style="text".
If a collection is defined in the mapping before the
value, the value will be always empty regardless of the
xml content. (This is only true for a style="text" value,
other types such as "attribute" work).
I constructed a very simple testcase to provoke the behaviour:
-------------------------------------------------------
binding file:
<?xml version="1.0" encoding="UTF-8"?>
<binding>
<mapping name="a" class="A">
<collection field="coll" item-type="java.lang.String">
<structure name="b">
<value name="c" style="attribute"/>
</structure>
</collection>
<value style="text" usage="optional" field="text"></value>
<value name="name" usage="optional" field="name"
style="attribute"></value>
</mapping>
</binding>
-------------------------------------------------------
Java class:
import java.util.ArrayList;
import java.io.FileInputStream;
import org.jibx.runtime.*;
public class A
{
ArrayList coll = new ArrayList();
String text;
String name;
public String toString()
{
return getClass()+" name="+name+" text="+text+" coll="+coll;
}
public static void main(String[] args)
{
try
{
IBindingFactory bfa = BindingDirectory.getFactory(A.class);
IUnmarshallingContext uc = bfa.createUnmarshallingContext();
Object o = uc.unmarshalDocument(new FileInputStream("data.xml"),
null);
System.out.println("Could read object: "+o);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
-------------------------------------------------------
Test xml:
<a name="a">text</a>
The output is:
Could read object: class A name=a text= coll=[]
-------------------------------------------------------
This means that the text was not read. If I declare the value with
style="text" as first element within the binding it seems to work,
but this is no real solution as it leads to serious problems when
working with abstract mappings that inherit from each other. Here it
cannot be guaranteed that the value with style="text" is always the
topmost element.
Any help would be appreciated.
Best regards,
Lars
-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users