how to ensure that an entire object graph is serializable?

  • Thread starter Christian Schuhegger
  • Start date
C

Christian Schuhegger

hi,

i've tried to search the web to find a reliable way to determin if an
object graph is serializable or not.

my main problem is this: if a class is not serializable at all i will
get a NotSerializableException. but when i have for example a super
class that does not implement serializable but has an appropriate empty
constructor and then i have a subclass that does implement serializable
then the fields of the superclass won't be serialized.

how do i find out if any class in an object graph does not implement
serializable. probably only via reflection?

i've already tried to (miss)use rmic with the -idl option and i expected
it to fail on classes where the super classes are not serializable. but
it does not. it just creates an empty superclass idl definition.

thanks for any comments!
 
M

Matt Humphrey

Christian Schuhegger said:
hi,

i've tried to search the web to find a reliable way to determin if an
object graph is serializable or not.

my main problem is this: if a class is not serializable at all i will
get a NotSerializableException. but when i have for example a super
class that does not implement serializable but has an appropriate empty
constructor and then i have a subclass that does implement serializable
then the fields of the superclass won't be serialized.

how do i find out if any class in an object graph does not implement
serializable. probably only via reflection?

i've already tried to (miss)use rmic with the -idl option and i expected
it to fail on classes where the super classes are not serializable. but
it does not. it just creates an empty superclass idl definition.

As you noted, you can determine whether it's serializable by attempting to
serialize it, including walking the graph yourself (which isn't that hard.)
The bigger question is what will you do if it's not serializable? If your
application requires objects to be serialized, transmitted and received,
you're going to have to do some design legwork in advance to make sure that
every object you need or intend to transmit will be serializable.

Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/
 
T

Tor Iver Wilhelmsen

Christian Schuhegger said:
how do i find out if any class in an object graph does not implement
serializable. probably only via reflection?

Use a Set with the class names or the classes themselves, and
recursively navigate using getMembers() from the "initial" class,
testing each class for Serializable (use isAssignableFrom()), until
you no longer have unresolved classes or one fails the test.
 
C

Christian Schuhegger

Matt said:
As you noted, you can determine whether it's serializable by attempting to
serialize it, including walking the graph yourself (which isn't that hard.)
The bigger question is what will you do if it's not serializable? If your
application requires objects to be serialized, transmitted and received,
you're going to have to do some design legwork in advance to make sure that
every object you need or intend to transmit will be serializable.

the problem is that we have to upgrade a legacy application to work with
network transmissions. therefore i have to be able to find out which
classes in the object graph are not serializable in a relyable way.

thanks for your info,
 
C

Christian Schuhegger

Tor said:
Use a Set with the class names or the classes themselves, and
recursively navigate using getMembers() from the "initial" class,
testing each class for Serializable (use isAssignableFrom()), until
you no longer have unresolved classes or one fails the test.

yes, this is a good idea, but there are not only members in the graph,
but also elements added to hashmaps or vectors or other collections. i
will have to think about this problem in more detail.

thanks for your info!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top