Note there are other serialization options that would also be valuable
to try. Here's one of them:
http://code.google.com/p/protobuf-gwt/
This might be an area where some development effort would really help.
Find a way to get case classes to serialize, so long as their argument
types are relatively simple (primitive types and other case classes).
Lex Spoon
Ah, right, I see the problem.
Have you verified that everything works for non-case classes in Scala?
For case classes, can you try putting a "var" in front of all the
field names, in addition to adding the extra constructor? It's ugly,
but it would be a starting point for coming up with something cleaner.
As far as what the cleaner thing is, if the above works, the following
ancient issue would be helpful:
http://code.google.com/p/google-web-toolkit/issues/detail?id=1054
GWT has long been talking about supporting serialization of final
fields, and there's even a patch, but it somehow still hasn't landed.
-Lex
I'm a little surprised about the empty arrays. It might be worth
pursuing that and trying to smooth out that ugly corner case.
Custom field serializers are an interesting idea! As you say, you
probably won't be able to write a single one that works for any case
class. However, there could be a scalac plugin that does the trick.
Every time the plugin saw a case class, it could generate a custom
serializer on the side for it.
It would be better if the core tools just worked right, though.
Plugins are a pain on users. I have dug a little into the relevant
parts of the GWT code--bringing back all sorts of memories!--and I
believe I have identified the line of code that emits the Java "new"
expressions that reconstruct objects coming off the wire:
If you scroll up a little, you will see a number of special cases,
e.g. for custom serializers. Perhaps there is a special case we could
come up with that would work for Scala?
This doesn't seem like something good to include in the initial patch
to GWT, but it is potentially a good followon patch. The first patch
would make Scala+GWT work at all, and this second one would make it
work more conveniently.
-Lex
I would not give up yet on custom serializers. The problems you
describe for collections already apply to Java. Java's List, Map, and
Set also have a gazillion subclasses, and serializing them doesn't
work all that well in practice. If I recall correctly, the best
practice we could come up with was to advise people to make final
subclasses of the major collection types and to use those final
subclasses in their DTO classes.
To do something similar for Scala, you could make a custom subclass of
Scala's Seq, Map, and Set. Internally, they would wrap a normal List,
Map, and Set. For serialization, you would supply a custom serializer
that does something reasonable and does *not* recurse into the member
types.
Note that a class with a custom serializer is always whitelisted as
serializable, even if it doesn't implement Serializable or
IsSerializable.
Also, note that the point of the whitelist is to avoid needing runtime
reflection, which leads to problems with optimization.
All this said, it might be good to stop and write up a wiki page or
some other form of doc summarizing what you have found with stock GWT
RPC. It sounds like a ton already works, despite the disappointments
about case classes and collections.
Lex Spoon
I would not give up yet on custom serializers. The problems you
describe for collections already apply to Java. Java's List, Map, and Set also have a gazillion subclasses, and serializing them doesn't work all that well in practice. If I recall correctly, the best
practice we could come up with was to advise people to make final subclasses of the major collection types and to use those final subclasses in their DTO classes.
To do something similar for Scala, you could make a custom subclass of
Scala's Seq, Map, and Set. Internally, they would wrap a normal List,
Map, and Set. For serialization, you would supply a custom serializer
that does something reasonable and does *not* recurse into the member
types.
All this said, it might be good to stop and write up a wiki page or
some other form of doc summarizing what you have found with stock GWT RPC. It sounds like a ton already works, despite the disappointments about case classes and collections.
Do you guys have a wiki setup somewhere already?