I have my GWT project, and another project that just has simple Domain Objects, and has nothing GWT specific.
In my Domain Objects project, I have a class Bob that has some primitive fields. Nothing special. He implements Serializable for the hell of it.
I wanted to return this type from a GWT service method. Learning that the service method can only return classes that implment GWT’s IsSerializable interface, I created a subclass of Bob, BobSO (Bob Service Object), and had it implement IsSerializable.
Basic project structure
proj> Bob.java
proj_gwt
proj_gwt > projgwt.gwt.xml
proj_gwt.client
proj_gwt.server
proj_gwt.shared > BobSO.java
I’m getting an error when running the service. It seems that it’s loading BobSO, and seeking the source for the superclass Bob, and can’t find the source.
“Errors in [path to file]
Line 6: No source code is avaiable for Bob did you forget to inherit a required
- Will by BobSO subclass work since he implements IsSerializable?
- It looks like GWT knows where BobSO is. What do I need to do to so it knows where the source to Bob.java is? I’ve tried creating a gwt.xml in my DOmain Objects project, but I’m not sure if it needs to list each class that should be visible, and how to import it in my GWT project.
1. Serializability
Implement either Serializable or IsSerializable, plus make sure, that the class fulfills the remaining requirements for GWT serializability (a no-args constructor, no final fields, …)
2. Locating the sources
You need to create a module to help GWT-RPC find the serializable classes [*].
The module “gwt.xml” can live in your domain project. Alternatively, if you you don’t want to touch the domain project, it can also live in your GWT project – just make sure to put it in the correct package:
DomainProject
GwtProject
Important notes
bar.domain.Bob.Note
<source path=""/>[*] By the way, it may be surprising, that defining a module for the dependency is usually not even strictly necessary in GWT. (It is however required when GWT-RPC is involved.) Try it with a simple example, if you like – GWT will find the sources by itself – as long as they’re on the GWT compiler’s class path