oracle xstream 配置,java – XStream隐式集合配置问题

我正在使用生成此类

XML的系统:

123 Main Street

Suite 123

Test City

AA

00000

两个addressLine元素应该是XStream隐式集合的一部分 – 我想调用getAddressLine()方法并获取List< String>输出.

我一直在使用XStream的教程,并且还没有弄清楚如何正确映射addressLine元素.在XStream’s Tweaking Output tutorial中有类似的用例,但没有提供示例代码:

Another use case are collections, arrays and maps. If a class has a

field that is a one of those types, by default all of its elements are

embedded in an element that represents the container object itself. By

configuring the XStream with the XStream.addImplicitCollection(),

XStream.addImplicitArray(), and XStream.addImplicitMap() methods it is

possible to keep the elements directly as child of the class and the

surrounding tag for the container object is omitted. It is even

possible to declare more than one implicit collection, array or map

for a class, but the elements must then be distinguishable to populate

the different containers correctly at deserialization.

In the following example the Java type representing the farm may have

two containers, one for cats and one for dogs:

06001

但是,此SO answer表明XStream场示例是不可能的.

我已经尝试过这个Java代码对我的Java代码进行单元测试,但还没有运气:

XStream xstream = new XStream(new StaxDriver());

xstream.alias("address", Address.class);

xstream.alias("addressLine", String.class);

xstream.addImplicitCollection(Address.class, "addressLines");

Address address = (Address) xstream.fromXML(

new FileInputStream("src/test/resources/addressTest.xml"));

我应该尝试其他任何配置更改吗?

注意:我目前正在使用XStream v1.2.2.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值