Skip to content Skip to sidebar Skip to footer

Java.util.linkedlist.node Can Not Be Assigned To Gwt Serializable?

I am getting many errors when i try to compile my GWT application. Some of them are [ERROR] com.google.gwt.xml.client.impl.AttrImpl is not default instantiable (it must have a zer

Solution 1:

Three maxims:

  • GWT Java is Java but not Java
  • GWT Java is actually Java-compiler-friendly Javascript.
  • Implementing Serializable may not be GWT Serializable

Can anything be serialized as long as it implements Serializable?

In the java SE/EE bytecode world, serialization is simpler. In the following class declaration:

classSpiderimplementsSerializable{
  String a;
  Integer b;
  Cobweb c;
}

Compiler would sail thro a and b because, String already has its own serialization codec (i.e. coder/decoder or marshaller/demarshaller). So does Integer.

Compiler then tries to see if Cobweb implements Serializable either by providing its own codec or Cobweb comprises Serializable members like

classCobwebimplementsSerializable{
  Boolean d;
  Double e;
}

Both d and e already have serialization codec provided by the courtesy of Sun/Oracle's stewardship of the Java language.

What if CobWeb allows generic arguments?

classCobweb <T>
implementsSerializable{
  Boolean d;
  T e;
}

Cobweb<Float> would be serializable because Java already has a serialization codec for Float.

However, unless Donkey has a custom serialization codec, the compiler would croak on the following

classSpiderimplementsSerializable{
  String a;
  Integer b;
  Cobweb<Donkey> c;
}

What does GWT serialable mean?

Isn't implementing Serializable enough? Why, is Google implementing a new Serializable interface? Nope. It is Google's fault but not Google's fault.

GWT UI Java is always compiled to Javascript before it can be run. The native code for GWT UI Java is Javascript not binary Java bytecode. For the plain and obvious reason that the browser runs only Javascript but not Java bytecode.

Binary Data and GWT

In most instances, implementing Serializable would make your class GWT serializable. Being GWT serializable means that there is GWT-generated Javascript code that exists to perform the codec when needed. i.e., the codec is in Java source not Java byte-code. The codec must be translatable to Javascript because the GWT serialization/deserialization runs on the browser.

However, there are many classes that GWT does not have a codec already. For example, GregorianCalender and most classes that require Reflection. GregorianCalender implements Serializable but GWT compiler does not have any codec for it in Java source code that can be translated into Javascript.

GWT-generated Javascript is incapable of run-time Reflection. So GWT compensates that deficiency by performing delayed binding of pre-compiled permutations of all possible code that you could use. I believe that GregorianCalendar performs some measure of Reflection and writing a GWT codec for GregorianCalendar would be too huge number of permutations of Javascript code. I believe that is the reason as well as is the reason for the absence of codec for many classes. Someone please correct me.

Back to the original question ....

java.util.LinkedList.Node<E>

So, for goodness' sake, what in the world is E? Did you substitute E with a GWT serializable?

Evidence from the stack trace (if I am even good at tracing a stack trace) indicates that you had not even bothered to substitute the generic argument with an actual type. By doing that, you are forcing GWT compiler to consider E as the class Object. And nobody knows how to serialize the class Object. You would be like the Pharaoh in Genesis 41 telling Joseph,

"Joseph please interpret my dream, but I have forgotten my dream, so you have to tell me about my dream too."

Solution 2:

As first line of stack says, to be serialized, class need to have constructor with no parameters or have custom serializer. java-custom-serialization here is topic about writing serializer

Post a Comment for "Java.util.linkedlist.node Can Not Be Assigned To Gwt Serializable?"