Discussion:
[castor-dev] castor unmarshall inheritance example
paul_oshea
2009-07-23 18:10:29 UTC
Permalink
Something very simple, I want to know the best way of unmarshalling xml that
contains class B which extends class A.

So here is the example

class A {
private Long uniId;

public getUniId() {
}
}

class B extends A {
private String name;

public String getName();
}

mapping.xml:

<class name="A">
<field name="uniId" type="long">
</field>
</class>

<class name="B" extends A>
<field name="name" type="String">
</field>
</class>


input xml:

<uniId>10001</uniId>



<name> myName </name>




java code:
Mapping mapping = new Mapping();
mapping.loadMapping( "mapping.xml" );

Unmarshaller unmar = new Unmarshaller(mapping);
/*what class goes here*/ unmar. unmarshal(new
FileReader("input.xml");

// what goes here in order to unmarshall input.xml and get the value of
uniId in class B
//so something like:
// B myB = (B)unmar. unmarshal(new FileReader("input.xml");
// Long uniId = myB.getUniId();

basically B will inherit the uniId from A and i want to know how i can
access that by reading in B(or A and b if necessary)

THanks,
pos
--
View this message in context: http://www.nabble.com/castor-unmarshall-inheritance-example-tp24631422p24631422.html
Sent from the Castor - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Loading...