Hi Andrey, Andrey Rahimov wrote:
> Thank you for your help and deep response! > > We found the problem it was our object model every object in our model has > > @XStreamAlias("response") > > for example > > @XStreamAlias("response") > public class AGPSRoutePoint extends ARoutePoint > > So now if I changing this to different names in unit-tests like > @XstreamAllia("ping"), @XstreamAlias("geo") it working well. > > We have old backend and big base of Android/iOS users with old won't > updated versions. The question is what approach you recommend us to use > to parse such xml?(Annotations will be most convenient way for us coz we > have around 50 model classes with additional logic) Your objects seemed to have a common parent (or implement a common interface) TypedInput. In this case you might define now an alias "response" for TypedInput and an own converter handling such a general TypedInput. You will now have to tell this converter what type it actually should convert. You can "talk" to it using a DataHolder (it's a very simple map). Instead of fromXML = xstream.fromXML(bodyString); You should invoke XStream with something like: DataHolder dataHolder = xstream.newDataHolder(); dataHolder.put(Converter.class, this.getClass()); InputStream in = new ByteArrayInputStream(bodyString.getBytes("utf-8")); fromXML = xstream.unmarshal(driver.createReader(in), null, dataHolder); "driver" is an instance, you may keep along to the XStream: Driver driver = new XppDriver(); // XStream default XStream xstream = new XStream(driver); The generic TypedInput converter should look like: class TypedInputConverter implements Converter { ConverterLookup lookup; TypedInputConverter(ConverterLookup lookup) { this.lookup = lookup; } boolean canConvert(Class type) { return type == TypedInput.class; } void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { throw ConverterException("Marshalling unsupported"); } Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Class realType = context.get(Converter.class); Converter converter = lookup.lookupConverterFor(realType); return converter.unmarshal(reader, context); } } This converter must have been registered: xstream.registerConverter(new TypedInputConverter(xstream.getConverterLookup())); This approach assumes that you no longer use the "response" alias for something else and that you do not (un)marshal direct instances of TypedInput. Otherwise you must give more information to your class hierarchy. Cheers, Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email