I have some XML files stored by XStream a while ago, and they include references to RandomAccessSubList, a class which is not visible beyond the package level and has no default constructor so XStream throws this error:
com.thoughtworks.xstream.converters.ConversionException: Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor : Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor
---- Debugging information ----
message : Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor
cause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message : Cannot construct java.util.RandomAccessSubList as it does not have a no-args constructor*
and this is the XML:
<customTimes class="java.util.RandomAccessSubList">
<l class="list">
<long>1302174300146</long>
<long>1302174305231</long>
<long>1302174310312</long>
etc.
I can't just write a converter for RandomAccessSubList because it's not visible outside the util package. How can I tell XStream to ignore the class for this attribute or how can I specify a converter for a class I can't reference?
Thanks in advance!
I got to the bottom of it - turns out xstream should handle that xml (it doesn't need a no-args constructor), the issue arose because I was using jdk 7 with an older version of xstream (1.3.1). See here http://code.google.com/p/pitestrunner/issues/detail?id=4. Moving back to jdk 6 fixed the issue (for various reasons i can't upgrade).
Before I realised that I did write a converter that worked for RandomAccessSubList if anyone needs it:
public class RandomAccessSubListConverter extends CollectionConverter {
public RandomAccessSubListConverter(Mapper mapper) {
super(mapper);
}
@Override
public boolean canConvert(Class arg0) {
return arg0.getName().equals("java.util.RandomAccessSubList");
}
@Override
public Object unmarshal(HierarchicalStreamReader reader,
UnmarshallingContext context) {
reader.moveDown();
ArrayList arrayList = new ArrayList();
populateCollection(reader, context, arrayList);
reader.moveUp();
return arrayList;
}
Thanks to anyone who was looking into for me!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With