Hi,
I am stuck on a mapping issue that doesn't seem to be clearly documented in
JiBX. The problem I find is not being able to map a class attribute which
is a collection and the object in the collection is a sub-class. This seems
doable and OK until I have to map an XML element to an attribute of the
superclass. Am I making sense here?
In the following example, I am mapping an Organisation, which has a
collection of Opportunity. Each Opportunity has in turn a collection of
Activity, which is a sub-class of AbstractLookupValue (this is not actually
an abstract class, but don't worry!).
The problem is that the Activity is not mapped. There is a setter in
AbstractLookupValue, called subTypeId, which determines the type of
Activity. This setter is not being called.
I would appreciate if you could give me assistance in making this work. An
example of the codes is as follows below.
<?xml version="1.0" encoding="UTF-8"?>
<binding>
<mapping name="abstractlookupvalue"
class="domain.AbstractLookupValue" abstract="true">
<value name="id" field="subTypeId" style="attribute"/>
</mapping>
<mapping name="activity" class="domain.Activity"
extends="domain.AbstractLookupValue">
<structure map-as="domain.AbstractLookupValue"/>
</mapping>
<mapping name="organisation" class="domain.Organisation">
<namespace uri="http://www.blablabla.org.uk/uploader"
default="elements"/>
<value name="partnerId" field="vbase2Id" style="attribute"/>
<collection name="opportunities" field="opportunities"
usage="required" create-type="java.util.ArrayList">
<structure name="opportunity"
type="domain.Opportunity">
<value name="uploaderId" field="vbase2Id"
style="attribute"/>
<value name="title" field="title"/>
<value name="summary"
field="shortDescription"/>
<value name="description"
field="description"/>
<value name="benefits" field="benefits"/>
<value name="requirements"
field="qualifications"/>
<collection name="activities"
field="activities" create-type="java.util.ArrayList">
<structure
map-as="domain.Activity"/>
</collection>
</structure>
</collection>
</mapping>
</binding>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<organisation
xmlns="http://www.blablabla.org.uk/uploader"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
partnerId="ufohybrid">
<opportunities>
<opportunity uploaderId="1">
<title>A</title>
<summary>B</summary>
<description>C</description>
<benefits>D</benefits>
<requirements>E</requirements>
<activities>
<activity id="2" />
</activities>
</opportunity>
</opportunities>
</organisation>
public class Activity extends AbstractLookupValue
{
// ...
}
public class AbstractLookupValue extends AbstractPersistable<Long>
{
// ...
}
public class Organisation extends AbstractPersistable<Long>
{
private List<Opportunity> opportunities = new
ArrayList<Opportunity>();
// getters, setters, and other attributes
}
public class Opportunity extends AbstractPersistable<Long>
{
// many class attributes, getters and setters seen in the
binding.xml
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users