I am trying to use BindingGenerator to automate xml serialization needs.

Consider the following Java classes:

public class SomeClass {
public String text;
}

public class ParentClass {
public String name;
public SomeClass[] data;
}

public class ChildClass extends ParentClass{
public String type;
}

Binding Generator command (jibxtools-beta2):
java -cp c:\apps\jibx\lib\jibx-genbinding.jar;c:\apps\jibx\lib\jibx-bind.jar;c:\apps\jibx\lib\jibx-extras.jar;c:\apps\jibx\lib\jibx-run.jar;. org.jibx.binding.BindingGenerator -v -a ParentClass ChildClass SomeClass

Generated Binding:
<?xml version="1.0" encoding="UTF-8"?>
<binding forwards="false" value-style="attribute">
 <mapping class="ChildClass" name="child-class">
   <value style="element" name="type" field="type" usage="optional"/>
   <structure map-as="ParentClass" name="parent-class"></structure>
 </mapping>
 <mapping class="SomeClass" name="some-class">
   <value style="element" name="text" field="text" usage="optional"/>
 </mapping>
 <mapping abstract="true" class="ParentClass">
   <value style="element" name="name" field="name" usage="optional"/>
<structure field="data" usage="optional" marshaller="org.jibx.extras.TypedArrayMapper" unmarshaller="org.jibx.extras.TypedArrayMapper"></structure>
 </mapping>
</binding>

1. Marshalling test (works ok):

Java Code:
IBindingFactory bfact = BindingDirectory.getFactory(ChildClass.class);
ChildClass cc = new ChildClass();
cc.name = "rob";
cc.type = "java";
SomeClass sc = new SomeClass();
sc.text = "hello";
SomeClass[] scArray = {sc};
cc.data = scArray;
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.marshalDocument(cc, "UTF-8", null, new FileOutputStream("C:\\child.xml"));

child.xml:
<?xml version="1.0" encoding="UTF-8"?>
<child-class>
  <type>java</type>
  <parent-class>
     <name>rob</name>
     <some-class>
        <text>hello</text>
     </some-class>
  </parent-class>
</child-class>

2.  Finally, unmarshalling test (fails)
Java Code:
IBindingFactory bfact = BindingDirectory.getFactory(ChildClass.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
ChildClass cc = (ChildClass)uctx.unmarshalDocument(new FileInputStream("C:\\child.xml"), null);

Exception message: Expected "parent-class" end tag, found "some-class" start tag (line 1, col 110)

-------
In my application I do not care about the xml lay-out, only using xml binding as a ser/deser mechanism, so any automatically generated binding that can do the job would be acceptable. Is this kind of situation supposed to be handled by the BindingGenerator tool? The documentation seems to indicate yes. (Arrays of complex type) If not, please let me know what modifications to above binding would fix this issue.

Thanks.




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to