I'm trying to serialize a simple hierarchy:
public class RootClass {
@Element
private final int a;
public RootClass( int a) {
this.a = a;
}
}
class SubClass extends RootClass {
@Element(name="b")
int b;
public SubClass() {
super(0);
this.b=0;
}
}
when I run
SubClass sub = new SubClass();
Serializer serializer = new Persister();
StringBuilderWriter writer = new StringBuilderWriter(1000);
serializer.write(sub, writer);
I get:
ConstructorException: Default constructor can not accept read only
@org.simpleframework.xml.Element(name=, data=false, type=void, required=true)
on field 'a' private final int
com.informatica.b2b.structurediscovery.serialization.tests.RootClass.a in class
com.informatica.b2b.structurediscovery.serialization.tests.SubClass
I couldn't find any way to make it work.
What is Serializer? if you want to serialize your object, you should implement the interface Serializable. Here is my code: