[Biojava-dev] Serial confusion :)

Keith James kdj@sanger.ac.uk
23 Oct 2002 13:50:03 +0100


I'm hoping someone who knows about serialization can elighten me.

I added a couple of test cases to SeqSerializationTest to test
(de)serialization of Features with FuzzyLocations. Fine and dandy,
because they all passed.

However, when I look at FuzzyLocation I can't understand why they
passed as FuzzyLocation has a reference

    private RangeResolver resolver;

which is a reference to a non-serializable object. However, all
supplied RangeResolvers are static and therefore don't get serialized.
I've read up a bit on serialization, but can't find a definitive
reference for what to expect in this situation.

So a bit of test code to find out...

class MyTest implements Serializable
{
	public static final FooI FOO_A;
	public static final FooI FOO_B;

	static
	{
		FOO_A = new Foo("a");
		FOO_B = new Foo("b");
	}

	FooI my_foo;

    // Pass one of MyTest.FOO_A or MyTest.FOO_B
	MyTest(FooI foo)
	{
        my_foo = foo;
	}

	public static interface FooI extends Serializable { }

	private static class Foo implements FooI
	{
		private String str;

		Foo(String str)
		{
			this.str = str;
		}

		public String toString()
		{
			return "Foo: " + str;
		}
	}
}

I think MyTest/FooI are analagous to FuzzyLocation/RangeResolver, but
MyTest is not serializable:

java.io.NotSerializableException: MyTest$Foo

So why can I serialize a FuzzyLocation?

cheers,

Keith

-- 

- Keith James <kdj@sanger.ac.uk> bioinformatics programming support -
- Pathogen Sequencing Unit, The Wellcome Trust Sanger Institute, UK -