简体   繁体   中英

xstream alias from different parameter

I try to address an advanced problem with mapping lists from my xml to my Java Objects.

I can give the problem a name: 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.

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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