Search the web
Sign In
New User? Sign Up
JSX-ideas · Ideas on Java Serialization for XML
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Inner Classes with JSX   Message List  
Reply | Forward Message #2195 of 2200 |
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



Mon May 25, 2009 12:06 pm

egroups_yow
Offline Offline
Send Email Send Email

Forward
Message #2195 of 2200 |
Expand Messages Author Sort by Date

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...
Brendan Macmillan
egroups_yow
Offline Send Email
May 25, 2009
12:07 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help