I have the following xml with measurement section, I want convert it to java objects. But I have problem with design POJO's object for this section. Can you help me please? Thanks
<root_element>
<element>some_value</element>
<element>some_value</element> // SOME OTHERS ELEMENT'S
<element>some_value</element>
<measurement> // BEGINING OF THE SECTION WHERE I HAVE A PROBLEM
<component>SO2</component>
<averaged_time>
<averaged_hours>1</averaged_hours>
<value>9.054</value>
</averaged_time>
<component>NO2</component>
<averaged_time>
<averaged_hours>1</averaged_hours>
<value>14.155</value>
</averaged_time>
</measurement> // END OF THE SECTION WHERE I HAVE A PROBLEM
<element>some_value</element>
</root_element>
I have something like this (I did not write here other parameters, those work without problem). JAXB return me in Measurement just last one "component" and "averaged_time" elements. I know that ArrayList <Measurement> is bad approach.
@XmlRootElement
public class root_element {
private ArrayList<Measurement> measurements;
public ArrayList<Measurement> getMeasurements() {
return measurements;
}
@XmlElement (name = "measurement")
public void setMeasurement(ArrayList<Measurement> measurements) {
this.measurements = measurements;
}
}
Measurement object
public class Measurement {
private String component;
private AveragedTime averagedTime;
public String getComponent() {
return component;
}
@XmlElement (name = "component")
public void setComponent(String component) {
this.component = component;
}
public AveragedTime getAveragedTime() {
return averagedTime;
}
@XmlElement (name = "averaged_time")
public void setAveragedTime(AveragedTime averagedTime) {
this.averagedTime = averagedTime;
}
}
AveragedTime object
public class AveragedTime {
private int averaged_hours;
private double value;
public int getAveraged_hours() {
return averaged_hours;
}
@XmlElement (name = "averaged_hours")
public void setAveraged_hours(int averaged_hours) {
this.averaged_hours = averaged_hours;
}
public double getValue() {
return value;
}
@XmlElement (name = "value")
public void setValue(double value) {
this.value = value;
}