java - Jaxb, Class has two properties of the same name -


with jaxb, try read xml file few element in xml file interesting, skip many element

xml content

xml try read

<?xml version="1.0" encoding="utf-8"?> <!--sample xml file generated xmlspy v2010 rel. 3 sp1 (http://www.altova.com)--> <flx:modelerep xsi:schemalocation="urn:test:mod_rep.xsd mod_rep.xsd" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:flx="urn:test:mod_rep.xsd"> <flx:documentheader>     <flx:identification v="04489"/> </flx:documentheader> <flx:timeseries>     <flx:identification v="test1a"/>     <flx:businesstype v="a01"/>     <flx:product v="123a"/>     <flx:resourceobject codingscheme="n" v="testa"/>     <flx:period>         <flx:timeinterval v="2011-07-02t00:00/2011-07-16t00:00"/>         <flx:resolution v="pt2h"/>         <flx:pt>             <flx:p v="1"/>             <flx:q unitcode="string" v="1.0"/>             <flx:a currencyidentifier="string" v="195.0"/>         </flx:pt>     </flx:period> </flx:timeseries> <flx:timeseries>     <flx:identification v="test2a"/>     <flx:businesstype v="a01"/>     <flx:product v="a123b"/>     <flx:resourceobject codingscheme="n" v="test2"/>     <flx:period>         <flx:timeinterval v="2011-07-02t00:00/2011-07-16t00:00"/>         <flx:resolution v="pt2h"/>         <flx:pt>             <flx:p v="1"/>             <flx:q unitcode="string" v="1.0"/>             <flx:a currencyidentifier="string" v="195.0"/>         </flx:pt>         <flx:pt>             <flx:p v="2"/>             <flx:q unitcode="string" v="1.0"/>             <flx:a currencyidentifier="string" v="195.0"/>         </flx:pt>     </flx:period> </flx:timeseries> </flx:modelerep> 

my class

@xmlrootelement(name="modelerep", namespace="urn:test:mod_rep.xsd") public class modelerep {    @xmlelement(name="timeseries")   protected list<timeseries> timeseries;    public list<timeseries> gettimeseries() {   if (this.timeseries == null) {       this.timeseries = new arraylist<timeseries>();   }   return this.timeseries;   }    public void settimeseries(list<timeseries> timeseries) {   this.timeseries = timeseries;   }  }  @xmlaccessortype(xmlaccesstype.field) @xmlrootelement(name = "timeseries") public class timeseries {  @xmlelement(name="resourceobject") protected ressourceobject resourceobject;  @xmlelement(name = "period") protected period period;  public ressourceobject getresourceobject() {     return this.resourceobject; }  public void setresourceobject(ressourceobject resourceobject) {     this.resourceobject = resourceobject; }  public period getperiod() {     return this.period; }  public void setperiod(period period) {     this.period = period; }  }  @xmlaccessortype(xmlaccesstype.field) @xmlrootelement(name = "resourceobject")  public class ressourceobject { @xmlattribute(name = "codingscheme") protected string codingscheme;  @xmlattribute(name = "v") protected string v;  public string getcodingscheme() {     return this.codingscheme; }  public void setcodingscheme(string codingscheme) {     this.codingscheme = codingscheme; }  public string getv() {     return this.v; }  public void setv(string v) {     this.v = v; } }  @xmlaccessortype(xmlaccesstype.none) @xmlrootelement(name = "period") public class period {  @xmlelement(name = "timeinterval") protected timeinterval timeinterval;  @xmlelement(name = "pt") protected list<pt> pt;  public timeinterval gettimeinterval() {     return this.timeinterval; }  public void settimeinterval(timeinterval timeinterval) {     this.timeinterval = timeinterval; }  public list<pt> getpt() {     if (this.pt == null) {     this.pt = new arraylist<pt>();     }     return this.pt; }  public void setpt(list<pt> pt) {     this.pt=pt; }  }  @xmlaccessortype(xmlaccesstype.field) @xmlrootelement(name = "timeinterval") public class timeinterval {  @xmlattribute(name = "v") private string timeintervalperiod;  public string gettimeintervalperiod() {     return this.timeintervalperiod; }  public void settimeintervalperiod(string timeintervalperiod) {     this.timeintervalperiod = timeintervalperiod; }  }  @xmlaccessortype(xmlaccesstype.field) @xmlrootelement(name = "pt") public class pt {  @xmlelement(name = "p") protected p p;  @xmlelement(name = "a") protected a;  public p getp() {     return this.p; }  public void setp(p p) {     this.p = p; }  public geta() {     return this.a; }  public void seta(a a) {     this.a = a; } }  @xmlaccessortype(xmlaccesstype.field) @xmlrootelement(name = "p") public class p { @xmlattribute(name = "v") protected string position;   public string getposition(){     return this.position; }  public void setposition(string position){     this.position=position; } }  @xmlaccessortype(xmlaccesstype.field) @xmlrootelement(name = "a") public class { @xmlattribute(name = "v") protected string calculatedamount;  public string getcalculatedamount() {     return this.calculatedamount; }  public void setcalculatedamount(string calculatedamount) {     this.calculatedamount = calculatedamount; } } 

when try read xlm file get

com.sun.xml.internal.bind.v2.runtime.illegalannotationsexception: 1 counts of illegalannotationexceptions class has 2 properties of same name "timeseries"     problem related following location:         @ public java.util.list testjaxp.modelerep.gettimeseries()         @ testjaxp.modelerep     problem related following location:         @ protected java.util.list testjaxp.modelerep.timeseries         @ testjaxp.modelerep 

i don't understand error

edit: use jaxb-impl-2.1.12

ok don't have error, when check object, timeseries null...

so maybe jaxb seem have problem flx?

i faced problem , set this.

@xmlrootelement(name="yourrootelementname") @xmlaccessortype(xmlaccesstype.field) 

this work 100%


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -