Why won’t my GWT object serialise?

by smctainsh on 19/05/2012

When porting a large project to the web using GWT, here’s a helpful hint when trying to decipher why serialization of client-side objects won’t work.

Initially, when attempting to serialise a spatial hypermedia frame as part of my Honours project, I found that GWT would report vague serialization issues, or no issues at all. The development mode console would give me no indication of an error whatsoever – it would merely call the onFailure method in the AsyncCallback<T> instance.

If you are working with a large project, you may be tempted to comment out fields within the serialised object, re-adding them one-by-one until the cause of the problem is uncovered. However, this means you have to comment out methods, and anything that may reference those fields. This can be quite troublesome on the whole, and lead to a tiresome chain of problems.

Instead, add the transient keyword to the front of the applicable field. Add this to all your fields, and one-by-one, remove the keyword from fields of the same type. Start with primitive types, then progress to more complex objects.

My problem? It turned out to be a matter of attempting to serialise an Object field – which, as you can tell, is a big no-no. This wasn’t clear at first glance, because the field was rarely used.

Hopefully this helps someone – GWT can be a tangled web to work with, but it’s definitely worth it when you work through the issues!

smctainsh@gmail.com

No comments yet.

Write a comment: