I have server written in java SE, and a client is written in android, when I serialize an object Map
in the client and then I pass it to the server and the server can't deserialize the object and vice versa. So, when I'm trying to deserialize another object like String
, or Date
, that's working fine.
Asked
Active
Viewed 561 times
-2

Noob Kraker
- 181
- 1
- 2
- 11
-
What type of serializing? – Dmitry Guselnikov Jun 05 '13 at 10:16
-
What kind of data is stored in your map? – AlexR Jun 05 '13 at 10:17
2 Answers
2
Map
s should usually be avoided in interfaces, especially when it involves serialization.
Instead, try to replace your map by an other data structure containing the same data.
For instance, create an object like:
public class MyObject implements Serializable {
Key keyOfMap;
Value valueOfMap;
}
And send a List<MyObject>
or equivalent.
This should avoid all your map problems.

Jean Logeart
- 52,687
- 11
- 83
- 118
-
-
but i wonder why the Map don't deserializes, because when I serialize in java SE the server deserializes the object well – Noob Kraker Jun 05 '13 at 10:29
1
HashMap itself is Serializable. The problem is that all keys / values it contains must be Serializable too if you want to serialize this map instance.

Evgeniy Dorofeev
- 133,369
- 30
- 199
- 275
-
-
I dont think so. Only classes that implement java.io.Serializable can be serialized with ObjectOutputStream.writeObject – Evgeniy Dorofeev Jun 05 '13 at 10:26