首先,我已阅读link text并且它无法解决我的问题。
我正在使用带别名的XStream。
Condition是具有多种不同实现的接口。我想删除class属性。我知道当实现类不明确时,XStream使用class属性,我可以为最多一个实现类设置一个别名。我想一起删除class属性并使用type属性加上其他子元素的存在来确定实现类。这可能吗?
这是我目前使用的XML:
<NextDestinations>
<Connector>
<DestinationId>2</DestinationId>
</Connector>
<Connector>
<DestinationId>3</DestinationId>
<condition class="com.orchestral.rhapsody.configuration.filter.condition.JavaScriptCondition" type="JAVASCRIPT">
...
</condition>
</Connector>
<Connector>
<DestinationId>4</DestinationId>
<condition class="com.orchestral.rhapsody.configuration.filter.condition.MessageTypeCondition">
<type>CONDITIONAL</type>
...
</condition>
</Connector>
<Connector>
<DestinationId>5</DestinationId>
<condition class="com.orchestral.rhapsody.configuration.filter.condition.MessageTypeCondition">
<type>CONDITIONAL</type>
...
</condition>
</Connector>
<Connector>
<DestinationId>6</DestinationId>
<condition class="com.orchestral.rhapsody.configuration.filter.condition.PropertyCondition">
<type>CONDITIONAL</type>
...
</condition>
</Connector>
<Connector>
<DestinationId>7</DestinationId>
<condition class="com.orchestral.rhapsody.configuration.filter.condition.FieldCondition">
<type>CONDITIONAL</type>
...
</condition>
</Connector>
<noMatchDestination>8</noMatchDestination>
<errorDestination>9</errorDestination>
</NextDestinations>
这是我想要的XML:
<NextDestinations>
<Connector>
<DestinationId>1</DestinationId>
</Connector>
<Connector>
<DestinationId>2</DestinationId>
<condition type="JAVASCRIPT">
...
</condition>
</Connector>
<Connector>
<DestinationId>3</DestinationId>
<condition type="CONDITIONAL">
...
</condition>
</Connector>
<Connector>
<DestinationId>4</DestinationId>
<condition type="CONDITIONAL"
...
</condition>
</Connector>
<Connector>
<DestinationId>5</DestinationId>
<condition type="CONDITIONAL">
...
</condition>
</Connector>
<Connector>
<DestinationId>6</DestinationId>
<condition type="CONDITIONAL">
...
</condition>
</Connector>
<Connector>
<DestinationId>7</DestinationId>
<condition type="CONDITIONAL"
...
</condition>
</Connector>
<noMatchDestination>8</noMatchDestination>
<errorDestination>9</errorDestination>
</NextDestinations>
答案 0 :(得分:1)
我设法通过别名接口的类型[xstream.aliasType(...)]来解决类属性问题,然而它使得无法反序列化,因为它显然无法创建接口的实例并且具有默认类不合适。
最终的解决方案是创建自定义转换器,这非常简单。
答案 1 :(得分:0)
根据您与XStream的关联程度,使用MOXy JAXB的以下方法对人们非常有用: