解组在Java Web服务的嵌套或复杂的数据元素 [英] Unmarshalling nested or complex data elements in JAVA Web services

查看:246
本文介绍了解组在Java Web服务的嵌套或复杂的数据元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发Java Web服务,并纷纷拿出输入到Web服务。输入具有数据元素和的最后一个元素是一个具有四个项目的ArrayList。我们能够拿到第一套,不能在ArrayList中元素的值,然后保存或将它们存储在数据库中。我们面临的挑战是让数组列表中的嵌套元素的值。

We are developing JAVA web services and have come up with input to the web services. The input has data elements and the last element is an Arraylist which has four items. We are able to get the values of first set of elements which are not in arraylist and then save or store them in a database. The challenge we have is to get the values of nested elements in arraylist .

我们使用以下code,但它是在抱怨或提供错误信息,即它不能看到(DataInfo.xml)的XML文件。我们认为这是由Web服务输入产生的,但我们不能看到它。

We are using the following code but it is complaining or giving error message that it cannot see (DataInfo.xml) XML file. Which we believe is being generated by the web services input but we cannot see it.

JAXBContext jaxbContext = JAXBContext.newInstance(DataInfo.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();          
DataInfo  EXitems = (DataInfo) jaxbUnmarshaller.unmarshal(new File("DataInfo.xml") );

我们如何才能确保XML是由code(应用程序)或什么是正从数组列表或值嵌套元素??最好的方式看到

How can we ensure that the XML is seen by the code (application) or what is the best way of getting values from arraylist or nested elements??

我们使用的是同样的code

Same code we are using

Main类

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DataInfo", propOrder = {"firstName","surname", "dateofBirth","studentAddress"})
@XmlRootElement(name = "dataInfo")                                          
public class DataInfo  implements Serializable {

}

ArrayList类

ArrayList Class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "studentAddress", propOrder = {"address1","address2", "town","country"})
@XmlRootElement(name = "studentAddress")                                            
public class studentAddress  implements Serializable {

}

我已删除的getter和setter发帖时缩短code

I have removed getters and setters to shorten the code when posting

请帮忙

推荐答案

像这样的东西为我工作,

Something like this worked for me,

@XmlElementWrapper(name = "ProfileList")
@XmlElement(name = "Profile")
private List<Profile> listOfProfiles;

有关XML结构一样,

....
<ProfileList>
    <Profile>......</Profile>
    <Profile>......</Profile>
</ProfileList>
....

这篇关于解组在Java Web服务的嵌套或复杂的数据元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆