public class Config {
private long dashboardTvId ;
private int freshTime ;
private long monitorGroupId ;
private int timeOfPareto ;
private int numOfPointer ;
private String name ;
private String title ;
private String theme ;
public long getDashboardTvId() {
return dashboardTvId;
}
public void setDashboardTvId(long dashboardTvId) {
this.dashboardTvId = dashboardTvId;
}
public int getFreshTime() {
return freshTime;
}
public void setFreshTime(int freshTime) {
this.freshTime = freshTime;
}
public long getMonitorGroupId() {
return monitorGroupId;
}
public void setMonitorGroupId(long l) {
this.monitorGroupId = l;
}
public int getTimeOfPareto() {
return timeOfPareto;
}
public void setTimeOfPareto(int timeOfPareto) {
this.timeOfPareto = timeOfPareto;
}
public int getNumOfPointer() {
return numOfPointer;
}
public void setNumOfPointer(int numOfPointer) {
this.numOfPointer = numOfPointer;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
@Override
public String toString() {
return "Config [dashboardTvId=" + dashboardTvId + ", freshTime=" + freshTime + ", monitorGroupId="
+ monitorGroupId + ", timeOfPareto=" + timeOfPareto + ", numOfPointer=" + numOfPointer + ", name="
+ name + ", title=" + title + ", theme=" + theme + "]";
}
}
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "configs")
@XmlAccessorType (XmlAccessType.FIELD)
public class Configs {
@XmlElement(name = "config")
private List<Config> configs;
public List<Config> getConfigs() {
return configs;
}
public void setConfigs(List<Config> configs) {
this.configs = configs;
}
@Override
public String toString() {
return "Configs [configs=" + configs + "]";
}
}
import java.io.StringReader;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
public class NestObject {
public static void main(String[] args) throws Exception {
String strdata =
" <site>\n"
+ " <siteName>siteName</siteName>\n"
+ " <configs>\n"
+ " <config>\n"
+ " <dashboardTvId>1</dashboardTvId><freshTime>30</freshTime><monitorGroupId>64990504</monitorGroupId><timeOfPareto>1</timeOfPareto><numOfPointer>30</numOfPointer><name>Name1</name><title>t1</title><theme>black</theme>\n"
+ " </config>\n"
+ " <config>\n"
+ " <dashboardTvId>2</dashboardTvId><freshTime>30</freshTime><monitorGroupId>64992631</monitorGroupId><timeOfPareto>1</timeOfPareto><numOfPointer>30</numOfPointer><name>Nam2</name><title>t2</title><theme>wihte</theme>\n"
+ " </config>\n"
+ " </configs>\n"
+ " </site>";
JAXBContext jaxbContext = JAXBContext.newInstance( Site.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
StringReader sreader = new StringReader( strdata);
Site site = (Site) jaxbUnmarshaller.unmarshal( sreader);
System.out.println(site.toString());
}
}