简体   繁体   English

来自不同参数的xstream别名

[英]xstream alias from different parameter

I try to address an advanced problem with mapping lists from my xml to my Java Objects. 我尝试解决将列表从xml映射到Java对象的高级问题。

I can give the problem a name: EVE XML API 我可以给问题起一个名字: EVE XML API

The link shows one problem I can't reverse engineer well: Same element tag with different content, but same attribute with different value. 链接显示了一个我无法很好地逆向工程的问题:相同的元素标签具有不同的内容,但是相同的属性具有不同的值。

It worked well to serialize objects to XML, but it can't convert back from the resulting XML to the object. 将对象序列化为XML效果很好,但是无法将生成的XML转换回对象。

I did this mapping of my various classes: 我对各种类进行了映射:

``` ```

XStream xStream = new XStream( );

// Aliases
xStream.alias("eveapi", CallList.class);
xStream.aliasAttribute(CallList.class, "version", "version");

xStream.alias("row", RowCallGroups.class);
xStream.aliasField("rowset", Result.class, "callGroups");
xStream.aliasAttribute(RowCallGroups.class, "groupID", "groupID");
xStream.aliasAttribute(RowCallGroups.class, "name", "name");
xStream.aliasAttribute(RowCallGroups.class, "description", "description");

xStream.addImplicitCollection(RowSetCallGroups.class, "callGroups");
xStream.alias("rowset", RowSetCallGroups.class);
xStream.aliasAttribute(RowSetCallGroups.class, "name", "name");
xStream.aliasAttribute(RowSetCallGroups.class, "key", "key");
xStream.aliasAttribute(RowSetCallGroups.class, "columns", "columns");

xStream.alias("row", RowCalls.class);
xStream.aliasField("rowset", Result.class, "calls");
xStream.aliasAttribute(RowCalls.class, "accessMask", "accessMask");
xStream.aliasAttribute(RowCalls.class, "type", "type");
xStream.aliasAttribute(RowCalls.class, "name", "name");
xStream.aliasAttribute(RowCalls.class, "groupID", "groupID");
xStream.aliasAttribute(RowCalls.class, "description", "description");

xStream.addImplicitCollection(RowSetCalls.class, "calls");
xStream.alias("rowset", RowSetCalls.class);
xStream.aliasAttribute(RowSetCalls.class, "name", "name");
xStream.aliasAttribute(RowSetCalls.class, "key", "key");
xStream.aliasAttribute(RowSetCalls.class, "columns", "columns");

``` ```

Any idea, how I can make a mapping based on the content of the name= attribute? 任何想法,如何基于name=属性的内容进行映射?

I wasn't able to post a solution last night, I do that now. 昨晚我无法发布解决方案,现在我可以了。

First: Posting all those classes would exceed the post limit by far. 第一:发布所有这些类将远远超过发布限制。 DB D B

Second: The point is, I had a wrong layout of my data. 第二:关键是,我的数据布局错误。

Solution: I have to use a custom converter. 解决方案:我必须使用自定义转换器。 The "native" ones can't convert that schema. “本机”不能转换该架构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM