使用XStream解组为静态类型

问题描述 投票:0回答:1

我有一个格式如下的XML文件:

<TRequest>
    <Item>
        <ItemIdentification>
            <ItemStandardID Qualifier="XX">egosdhgsuh</ItemStandardID>
        </ItemIdentification>
    </Item>
    <Item>
    ....
    </Item>
</TRequest>

从相关的WSLD的XSD开始,我使用JaxB生成了Java代码。这给了我以下层次结构:

public class TRequest extends Request {

    protected List<TRequest.Item> item;

    public static class Item {

        protected TRequest.Item.ItemIdentification itemIdentification;

        public static class ItemIdentification {

            protected TRequest.Item.ItemIdentification.ItemStandardID itemStandardID;

            public static class ItemStandardID {

            }

        }

    }

}

我正在尝试使用Item读取TRequest中的XStreamMarshallers:

    final XStreamMarshaller unmarshaller = new XStreamMarshaller();
    final ImmutableMap<String, ?> of = ImmutableMap.of(
            "Item", TRequest.Item.class,
            "ItemIdentification", TRequest.Item.ItemIdentification.class
    );
    unmarshaller.setAliasesByType(of);

但是当我尝试解组时,我收到以下错误:

org.springframework.oxm.UnmarshallingFailureException: XStream unmarshalling exception; nested exception is com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field com.mycompany.TRequest$Item.ItemIdentification
---- Debugging information ----
field               : ItemIdentification
class               : com.mycompany.TRequest$Item
required-type       : com.mycompany.TRequest$Item
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /Item/ItemIdentification
line number         : 2
version             : 4.3.13.RELEASE
-------------------------------

在上面对setAliasesByType的调用中,我尝试了诸如Item.ItemIdentificationItem$ItemIdentification等之类的东西作为TRequest.Item.ItemIdentification.class的关键映射。

实现这一目标的正确方法是什么?

java xstream jaxb2
1个回答
0
投票

我相信除了定义正确的类之外,还需要将这些类之间的关系定义为变量。

即。

public class TRequest extends Request {
    Item Item;
}

public class Item {
    ItemIdentification ItemIdentification;
}


public class ItemIdentification {
    ItemStandardID ItemStandardID;
}

public class ItemStandardID {
    String Qualifier;
}

等等

© www.soinside.com 2019 - 2024. All rights reserved.