[Simple-support] problem with generic list
Brought to you by:
niallg
|
From: Paulo F. <pau...@gm...> - 2007-07-14 11:00:56
|
hello,
i'm trying to use simple and so far it's been helpful. however, i'm
facing some difficulty with the problem sketched below:
@Root
class C {
@Element
String data;
C(String data){
this.data=data;
}
}
class A<T> {
@ElementList // LINE (1)
List<T> elements; // LINE (2)
A(){
elements = new ArrayList<T>(); // LINE(3)
}
void add(T t) {
elements.add(t);
}
}
@Root
class B {
@Element
A<C> aC;
B() {
aC = new A<C>();
}
}
public void test() {
B b = new B();
b.aC.add(new C("hello"));
b.aC.add(new C("world"));
Serializer serializer = new Persister();
File dest = new File("test.xml");
try {
serializer.write(b,dest);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
with this code, it throws
org.simpleframework.xml.load.ElementException: Unable to determine
type for @org.simpleframework.xml.ElementList(inline=false, type=void,
required=true, data=false, name=, parent=)
i think i must add some type attribute to LINE (1), but don't know
exactly how to do it.
i also tryed to replace LINE(2) and LINE (3) by
List<Object> elements; // LINE (2*)
elements = new ArrayList<Object>(); // LINE(3*)
but then it gives
org.simpleframework.xml.transform.TransformRequiredException:
Transform memex.common.test.MapSerialisationAdaptorTest$CTransform is
required for class memex.common.test.MapSerialisationAdaptorTest$C
i might be missing something very elementary and i'd really appreciate
if anyone could help me.
thanks in advance,
paulo
|