Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.Serializable and HashMap

 
Rainer Spruenken
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need some help with serialization. In my app I use a custom object which contains HashMap<String, ArrayList<String>>.
When I try to tranfer this object to the server I get some serialization exception
(was not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field serializer.
For security purposes, this type will not be deserialized.)
I tried to use a custom field serializer without any luck.
The Problem is that I MUST use java.io.Serializable and cannot use IsSerializable which works fine. Is there a reliable way
to use java.io.Serializable with my HashMap?


Regards and Thanke Rainer
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

HashMap already implements Serializable It is not the problem.
Is your custom object serializable
 
Rainer Spruenken
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick reply, can you please be clearer? I read a couple of threads about this topic and I think I get lost. My custom object consists of Strings, Boolean, Long and this HashMap. What do you think is wrong?

Rainer
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I meant was does your custom object implement serializable?
Let's make it easy. Show us your custom object code. (Don't forget to UseCodeTags though ;) )
 
Rainer Spruenken
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my object

 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
Can you also show us the full exception stack trace?
 
Rainer Spruenken
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And here is the error message

 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your Report under shared?
If yes, then I cannot help further than suggesting a full clean build
 
Rainer Spruenken
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the object it is not under shared...
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha!
/client - all your UI code goes here
/server - all your server code goes here
/shared - all your data code goes here

Just refactor under shared and you should be good

 
Rainer Spruenken
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, I will give it a try. Thanks a lot for your help. Regards Rainer
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha!
/client - all your UI code goes here
/server - all your server code goes here
/shared - all your data code goes here

Just refactor under shared and you should be good


Maneesh!! are you sure, this is going to make a difference. whatever you have written is a convention in my opinion (I strongly agree that we all should organize classes like this in a GWT application.)
Both the client and shared packages are on the GWT client side.
There is no any difference between the client & shared packages. please correct me if i am wrong.

Thanks
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rainer,

if the issue still persists, just change the Map to HashMap & List to ArrayList ( or any other implementer which you are using) and give it a try .
Providing concrete datatypes sometimes resolves the serialization issues and also enhances the performance.

Thanks
 
Rainer Spruenken
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thank you for the reply, I will try using the concrete types.

Regards Rainer
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
avi sinha wrote:
Aha!
/client - all your UI code goes here
/server - all your server code goes here
/shared - all your data code goes here

Just refactor under shared and you should be good


Maneesh!! are you sure, this is going to make a difference. whatever you have written is a convention in my opinion (I strongly agree that we all should organize classes like this in a GWT application.)
Both the client and shared packages are on the GWT client side.
There is no any difference between the client & shared packages. please correct me if i am wrong.

Thanks


It is a convention and a good convention at that. Remember, anything (including UI and data) has to be Java<->JS translatable. By default, the GWT "compiler" is configured to pick everything under client and shared.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic