Reputation: 11
I'm quite new on 'StackExchange', so pls excuse if my query asked earlier or not particularly clear.
I'm using XStream class to parse the response XML into JAVA object (using fromXML() method). I have created on utility class (say XStreamUtil - a singleton class) and configured different model class in it using statement like "XSTREAM.alias("NewDataSet", Transactional.class);".
Now the problem is - I'm getting XML from third party with same parent node (e.g. ) as response for different APIs. So, if I use code like below -
XSTREAM.alias("NewDataSet", Transactional.class);
XSTREAM.alias("NewDataSet", Open.class);
XSTREAM.alias("NewDataSet", Details.class);
{ XStream fails to parse response for first two classes (Transactional & Open) and it trying to parse it through 'Details.class' (the last one configured). This throws exception like below -
brilliance.model.report.notify.Details.Transactional
---- Debugging information ----
field : Transactional
class : com.brilliance.model.report.notify.Details
required-type : com.brilliance.model.report.notify.Details
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /NewDataSet/Transactional
version : 1.4.7
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$Un knownFieldException: No such field com.brilliance.model.report.notify.Details.Transactional
---- Debugging information ----
field : Transactional
class : com.brilliance.model.report.notify.Details
required-type : com.brilliance.model.report.notify.Details
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /NewDataSet/Transactional
version : 1.4.7
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.handleUnknownField(AbstractReflectionConverter.java:495)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.do Unmarshal(AbstractReflectionConverter.java:351)
.. .. ..
My question here is - Do we have a way to define same alias for two different java classes to be use through XStream? (
Upvotes: 1
Views: 787
Reputation: 11
I too had similar problem. Problem resolved by creating new xstream instance for each class and then process the annotation.
Upvotes: 1