I'm trying to read an XML like this to an object using XStream:
<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>
Everything is working as they should except the class="ChangeAttributeAction"
part.
I have in my Behavior class:
@XStreamAlias("class")
@XStreamAsAttribute
String classAtt = "";
Even tough I'm aliasing the field name, it gives the error:
Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: ChangeAttributeAction : ChangeAttributeAction
---- Debugging information ----
message : ChangeAttributeAction
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : ChangeAttributeAction
class : projectmerger1.Behaviors
required-type : projectmerger1.Behaviors
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
It used to work somehow, but now it doesn't. I used to treat objects differently but I cannot find out what I'm doing different to effect this. Also upon my research ->link<- I learned that trying NO_REFERENCE mode might work, but it didn't in my case.
I solved it by adding:
xstream.aliasSystemAttribute("", "class");
I have no idea why it works, but it works. Thanks anyway :)