I would like to serialize a non-static inner class in my java program. Though this is not allowed because my inner class (by default) has a reference to its outer class (which in this case is not serializable) so if I try to serialize it I get a NullPointerException for the outer class.

So is there a way to override the reference to the outer class and set it to transient so that it is not serialized by initialized every time and object of the inner class is created?