问题
I have following xml response from web service which need to map to java class.
<api1Response>
<timeStamp>06/24/2016 07:45:10</timeStamp>
<ippProjectName>xyz</ippProjectName>
<project>
<projectId>1</projectId>
<projectName>ABC</projectName>
<dataDate>06/06/2016</dataDate>
</project>
<project>
<projectId>2</projectId>
<projectName>PQR</projectName>
<dataDate>06/06/2016</dataDate>
</project>
</api1Response>
I have mapping class like
class api1Response{
String timeStamp;
String ippProjectName;
//how to map project
}
As project tags not having any parent element how i can map it to List using jaxb. I know it will be easy if "project" tags having parent elements like "projects" but response is not in my control and i still need to parse it with jaxb.
回答1:
Just using XmlElement over a list of projects shoud do the trick :
class api1Response{
String timeStamp;
String ippProjectName;
@XmlElement(name="project")
List<Project> projects;
}
来源:https://stackoverflow.com/questions/38008261/how-to-map-xml-fields-without-parent-tag-to-java-list