lishunli / kryo

Automatically exported from code.google.com/p/kryo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

MapSerialisation failing #109

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
HI, I tried using the Map serialisation for which I find very little actual 
examples. I want to serialise a hashMap<String, Object> and deserialize it

My code below
HashMap<String, Object> hm = new HashMap<String, Object> ();
hm.put("a", "woozle");
hm.put("b", 5);
Kryo kryo = new Kryo();
ByteBuffer buffer = ByteBuffer.allocate(1024);
MapSerializer serializer = new MapSerializer(kryo);
        kryo.register(HashMap.class, serializer, true);
        kryo.register(Object.class, serializer, true);

        serializer.setKeyClass(String.class);
        serializer.setKeysCanBeNull(false);
        serializer.setValuesCanBeNull(true);        
        serializer.writeObjectData(buffer, hm);

buffer.flip();

MapSerializer serializer = new MapSerializer(kryo);
        kryo.register(HashMap.class, serializer, true);
        kryo.register(Object.class, serializer, true);

        HashMap<String, Object> hm2 = serializer.readObjectData(buffer, HashMap.class); 

System.err.println(hm2.toString());

What is the expected output? What do you see instead?
I expect to see the following HashMap to come out
{b=5, a=woozle}
instead I see {false=woozle}

What version of the Kryo are you using?
I am using version 2.14

Original issue reported on code.google.com by schelfho...@gmail.com on 12 Apr 2013 at 3:18

GoogleCodeExporter commented 9 years ago
Hi,

Since Kryo is at version 2.21 now and 2.22 is in development, could you try if 
your problem is still present in those more up-to-date versions? A lot of bugs 
were fixed since 2.14

Original comment by romixlev on 27 Apr 2013 at 6:54

GoogleCodeExporter commented 9 years ago
Can reopen if the OP comes back with the requested info.

Original comment by nathan.s...@gmail.com on 11 Jun 2013 at 7:53