Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Xstream和将保留关键字用作XML属性的变通方法。(“类”)_Java_Xml_Xstream - Fatal编程技术网

Java Xstream和将保留关键字用作XML属性的变通方法。(“类”)

Java Xstream和将保留关键字用作XML属性的变通方法。(“类”),java,xml,xstream,Java,Xml,Xstream,我正在尝试使用XStream将这样的XML读入对象: <behavior id="id384781" class="ChangeAttributeAction" enabled="true"> <attributes> <text id="name">Change Attribute</text> <text id="bundleName">ChangeAttribute.behavi

我正在尝试使用XStream将这样的XML读入对象:

    <behavior id="id384781" class="ChangeAttributeAction" enabled="true">
      <attributes>
        <text id="name">Change Attribute</text>
        <text id="bundleName">ChangeAttribute.behavior</text>
        <text id="targetAttribute">game.devices.touches.touch1.y</text>
        <text id="RHS">
          <expression>
            <string>acos(x)</string>
          </expression>
        </text>
      </attributes>
    </behavior>
即使我对字段名使用别名,也会出现以下错误:

线程“main”com.thoughtworks.xstream.converters.ConversionException中的异常: ChangeAttributeAction:ChangeAttributeAction

----调试信息--

消息:更改属性

导致异常:com.thoughtworks.xstream.mapper.CannotResolveClassException

原因消息:更改属性

:项目合并1.行为

所需类型:项目合并1.行为

转换器类型:com.thoughtworks.xstream.converters.reflection.ReflectionConverter

它过去不知怎么起作用,但现在不行了。我过去对待物体的方式不同,但我不知道我做了什么不同的事情来实现这一点。在我的研究中->我补充道:

xstream.aliasSystemAttribute("", "class");

我不知道它为什么起作用,但它起作用了。无论如何,谢谢:)

名为
class
的属性对XStream有特殊意义-如果您有一个具有特定声明类型的属性,但您为该属性提供的值是一个子类型,那么XStream使用
class
来记录值的实际类型。此
调用禁用此逻辑。
xstream.aliasSystemAttribute("", "class");