Serializable fumbling
Just a small post today; whilst working with Spring Web Flow and Spring's JSP form:input tag, I was noticing one of my fields going blank. Convinced my code was somehow not mapping correctly, I looked everywhere about, trying to work out why it wasn't being kept.
I really should have noticed the significance sooner of the object reference changing between calls, even though in theory the object was instantiated only once. I think somewhere back in my mind I remembered a bit of a serializable issue once before, but unfortunately it didn't come up until after an hour of trying work out what was going wrong.
And in the end, the problem turned out to be that I hadn't defined my parent class (which held the disappearing variable) to be serializable, but had just done it on my child class. In essence, I'd missed a step in a valid serializable path.
Now, maybe I'm a bit cynical, but if a child class is defined serializable, isn't the parent implicitly serializable too? Obviously not, and thinking about it, I can sort of see why not since then someone could subclass something which was not designed to be serializable and whack on "implements serializable". I guess what I would have preferred happen is for the JVM to warn me about the potential issue here - maybe the Eclipse IDE should have too.
It's nice to find an area of knowledge which I didn't even realise I was weak in and correct that, but the road to understanding isn't always as fun as I'd like... whoa, very zen;P
0 comments:
Post a Comment