在messagepack中,从MapValue获取值时出错. [英] In messagepack, error while getting value from MapValue.. Please help me
本文介绍了在messagepack中,从MapValue获取值时出错.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用messagpack.write(map)
序列化地图.在使用messagepack.read(byte[])
反序列化期间,我得到了MapValue
.但是我无法使用MapValue.get(key)
获取值.在下面看这个问题
I'm trying to serialize map using messagpack.write(map)
. During deserialization using messagepack.read(byte[])
i got MapValue
. But I cannot fetch the values using MapValue.get(key)
. Look this problem below
HashMap<Object,Object> map = new HashMap<Object, Object>();
map.put(1,"ONE");
map.put("ONE","TWO");
MessagePack m= new MessagePack();
byte[] b = m.write(map);
MessagePack m1 = new MessagePack();
MapValue value = (MapValue)m1.read(b);
System.out.println(value);// here I am getting {1:"ONE",2:"TWO"}
System.out.println( value.get(1)); // printing the value for key 1. I am getting null.
请对此提供帮助.谢谢.
Please help on this.. Thanking you.
Nausadh
推荐答案
您需要使用ValueFactory并转换键才能使用Value接口.并不是很直观
You need to use ValueFactory and convert key to use a Value interface. It's not really intuitive
// instead of value.get(1) use following
System.out.println(value.get(ValueFactory.createIntegerValue(1)));
// if the key would be a String use:
System.out.println(value.get(ValueFactory.createRawValue("key")));
这篇关于在messagepack中,从MapValue获取值时出错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文