HashMap Serialization


I’m currently trying to learn SpiderMonkey, but I have a little issue with Serializing a HashMap

[java]import java.io.IOException;

import java.util.HashMap;

import com.jme3.network.connection.Client;

import com.jme3.network.connection.Server;

import com.jme3.network.events.MessageAdapter;

import com.jme3.network.message.Message;

import com.jme3.network.serializing.Serializable;

import com.jme3.network.serializing.Serializer;

public class HashMapSerializationTester extends MessageAdapter



public static class TestSerializationMessage extends Message


private final HashMap<String, Object> hashmap = new HashMap<String, Object>();

public TestSerializationMessage()






public void messageReceived(Message msg)


TestSerializationMessage cm = (TestSerializationMessage) msg;

System.out.println("recieved: " + cm.hashmap.values() + " <- Error ");


public static void main(String[] args) throws IOException, InterruptedException



Server server = new Server(5110, 5110);


Client client = new Client(“localhost”, 5110, 5110);



server.addMessageListener(new HashMapSerializationTester(), TestSerializationMessage.class);

TestSerializationMessage message = new TestSerializationMessage();

message.hashmap.put(“messagetest1”, “adwwda”);

message.hashmap.put(“messagetest2”, 3.55f);

System.out.println("sent: " + message.hashmap.values());





Can somebody tell me how to fix this?

Oh now I found the problem

private final HashMap<String, Object> hashmap = new HashMap<String, Object>();

shoulnt be declared as final !! Thats why its not overwritten by serialisation

Thanks anyway ^.^

1 Like