List users,

I'm having an issue with trying to map a collection of (sorta)-abstract 
objects. The issue is that, in the XML that I'm unmarshalling, the overall 
structure is
the same, but the element name will differ. Here's an example:

                <ResponseObject>
                        <CatTable>
                                <name>Boots</name>
                                <tp_cd>1001</tp_cd>
                        </CatTable>
                        <CatTable>
                                <name>Fluffy</name>
                                <tp_cd>1002</tp_cd>
                        </CatTable>
                        .....
                </ResponseObject>

The next XML I will unmarshall (from the same service call) is like this:

                <ResponseObject>
                        <DogTable>
                                <name>Rex</name>
                                <tp_cd>1003</tp_cd>
                        </DogTable>
                        <DogTable>
                                <name>King</name>
                                <tp_cd>1004</tp_cd>
                        </DogTable>
                        .....
                </ResponseObject>

All I really need is a class for Animal, with no differentiation between 
cats, dogs, beavers, etc., and there are over a hundred animals. If I have 
an Animal class, like this:

public class Animal {
        private String name;
        private String typeCode;
}

I want to unmarshall to an Animal object, since that is all I need in this 
case. There is NO Cat or Dog class. All responses will look the same with 
the exception of the element name (like CatTable, DogTable).

If I define my unmarshalling XML like this:

        <mapping name="ResponseObject" class="ResponseObject">
            <collection field="animals"  item-type="Animal" />
        </mapping>

I can then do the following for just a single animal:

        <mapping name="CatTable" class="Animal" abstract="true">
            <value name="name" field="typeValue" usage="required"/>
            <value name="tp_cd" field="typeCode" usage="required"/>
        </mapping>

If I try to define a second animal:

        <mapping name="DogTable" class="Animal" abstract="true">
            <value name="name" field="typeValue" usage="required"/>
            <value name="tp_cd" field="typeCode" usage="required"/>
        </mapping>

I get an error because the Animal class is multiply declared. 

The bottom line is that there seems to be no way to have an element name 
map to anything in JiBX without actually having a class that it concretely 
maps to. I have tried many combinations of things to get this to work, and 
can't find a solution. What I don't want to have to do is create classes 
like this:

        public class Dog extends Animal {}

        public class Cat extends Animal{}

and have hundreds of class files. 

I have also tried:

        <mapping class="Animal" abstract="true" type-name="lookup"      >
            <value name="name" field="name" usage="required"/>
            <value name="tp_cd" field="typeCode" usage="required"/>
         </mapping>
        <mapping name="CatTable" map-as="lookup" />
        <mapping name="DogTable" map-as="lookup" />

with no success. I have tried many other variants, all with new 
interesting errors to read up on. 

One of the justifications for this is that I want to be able to add a new 
Animal to my zoo without creating a class for it, so that through JiBX and 
Spring alone I can configure my app. The actual XML and objects are not 
those you see above, but the example is analogous and simple. 

I appreciate any thoughts on this.

Brian
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to