Hi Teody,
Yes, JSX can serialize inner classes.
JSX is a precise re-implementation of Java serialization, so if Java
serialization can do it, JSX can too.
Here is an instance of the example you gave, and its XML:
A a = new A();
Inner ia = a.new Inner();
ia.listOfA = new ArrayList();
ia.listOfA.add(new A());
ia.listOfA.add(new A());
try {
new JSX.ObjectWriter().writeObject(ia);
} catch (Exception e) {
e.printStackTrace();
}
<?xml version='1.0' encoding='UTF-8'?>
<!-- jsx.org, (c) -->
<jsx major='1' minor='1' format='JSX.DataReader'>
<object id='i0' class='A$Inner' superclasses=''>
<declaredClass class='A$Inner'>
<default>
<collection field='listOfA' id='i1' class='java.util.ArrayList'>
<object id='i2' class='A' superclasses=''>
<declaredClass class='A'>
<default/>
</declaredClass>
</object>
<object id='i3' class='A' superclasses=''>
<declaredClass class='A'>
<default/>
</declaredClass>
</object>
</collection>
<object field='this$0' id='i4' class='A' superclasses=''>
<declaredClass class='A'>
<default/>
</declaredClass>
</object>
</default>
</declaredClass>
</object>
</jsx>
Note that the XML includes the inner classname ("A$Inner"), and the
inner class's hidden field that refers to the outer class ("this$0").
Note also that if you serialize the outer class (variable a in the
above), you won't see the inner class, because the outer class doesn't
have a reference to it. The only reference is from the inner class to
the outer class. This isn't an issue in practice, because it is just
the same as Java serialization: if it works there, it works here.
Let me know if you have any other questions.
kind regards,
Brendan Macmillan
On 25/05/2009, Teody <teody...> wrote:
> Hi,
>
> Can your product serialize private inner classes?
> My class structure is this:
> public class A {
> private class Inner {
> List<A> listOfA;
> }
> }
>
> It is immutable so I can't change the design. What we are looking for is a
> serialization library that can serialize the inner class. Java serialization
> works but it would be a good option to have something that's human readable.
>
> Thanks
> Teody
--
The competent programmer is fully aware of the strictly limited size
of his own skull; therefore he approaches the programming task in full
humility, and among other things he avoids clever tricks like the
plague. - Dijkstra