Advertisement
Advertisement
| 02.13.2008 at 08:33AM PST, ID: 23160072 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: |
@XmlRootElement
class Foo {
@XmlElement
String a;
@XmlElement(required=true)
String b;
protected SubClass c;
public SubClass getSubClass(){
return c;
}
public SubClass setSubClass(SubClass sc){
this.c = sc;
}
}
-------------------------------------------------------
public class SubClass
-------------------------------------------------------
protected long[] local_long ;
public long[] get_long(){
return local_long;
}
public void set_long(long[] param){
this.local_long = param;
}
-------------------------------------------------------
myJaxb.java
-------------------------------------------------------
JAXBContext jc = JAXBContext.newInstance(new Class[] {jaxb.Foo.class});
Unmarshaller u = jc.createUnmarshaller();
Foo fooObj = (Foo)u.unmarshal(
new FileInputStream( "foo.xml" ) );
---------------------------------------
foo.xml
----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<foo>
<a>1</a>
<b>2</b>
<subClass>
<long>13</long>
<long>44</long>
</subClass>
</foo>
|