Hi. It's my first post.
I have a custom marshaller called by many structures/collections but
from my marshaller I can't read structure/collection name.
Its caused by a wrong call to marshaller constructor: in spite of my
binding.xml configuration, name param value in marshaller constructor is
always the same.
I looked in archive for a solution but I didn't find anything.
Can someone help me?
I'm using jibx 1.2.2 and Java 1.6.
Here a simplified version of all my files.
binding.xml:
---
<?xml version="1.0" encoding="UTF-8"?>
<binding direction="output">
<mapping name="root" class="packagename.Root">
<value name="id" get-method="getId" />
<structure name="a_child" field="aClass"
marshaller="packagename.Marshaller"/>
<structure name="another_child" field="anotherClass"
marshaller="packagename.Marshaller"/>
</mapping>
<mapping name="AClass" class="packagename.AClass">
<value name="id" get-method="getId" />
</mapping>
<mapping name="AnotherClass" class="packagename.AnotherClass">
<value name="id" get-method="getId" />
</mapping>
</binding>
---
Custom marshaller Java code:
---
public class Marshaller implements IMarshaller, IAliasable
{
private int index;
private String name;
public Marshaller(int index, String name)
{
// Here the mistake: in every call
// these variables have always the same value
this.index = index;
this.name = name;
}
public boolean isExtension(String index)
{
return false;
}
public void marshal(Object obj, IMarshallingContext ictx)
throws JiBXException
{
MarshallingContext ctx = (MarshallingContext) ictx;
ctx.startTag(this.index, this.name);
((IMarshallable) obj).marshal(ictx);
ctx.endTag(this.index, this.name);
}
}
---
I expect this output:
---
<?xml version="1.0" encoding="UTF-8"?>
<root>
<id>1</id>
<a_child>
<AClass>
<id>2</id>
</AClass>
</a_child>
<another_child>
<AnotherClass>
<id>3</id>
</AnotherClass>
</another_child>
</root>
---
But my output is:
---
<?xml version="1.0" encoding="UTF-8"?>
<root>
<id>1</id>
<a_child>
<AClass>
<id>2</id>
</AClass>
</a_child>
<a_child> <!-- Here the mistake -->
<AnotherClass>
<id>3</id>
</AnotherClass>
</a_child>
</root>
---
What's wrong with what I am doing?
Thanks a lot
--
V. Marco Carnazzo
------------------------------------------------------------------------------
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users