[英]Json, Jackson and serialization
I've started to using Json with Jackson library and i found little problem. 我已经开始在Jackson图书馆中使用Json,但发现的问题很少。
I'm creating Json object: 我正在创建Json对象:
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> userInMap = new HashMap<String, Object>();
then i'm adding fields: 然后我添加字段:
userInMap.put("user", "active");
userInMap.put("uuid", uuid);
And after all when im trying to output this object i have Json object but without "
, i mean i supposed to have: 毕竟,当我尝试输出此对象时,我有Json对象,但没有
"
,我的意思是我应该有:
{"user":"active", "uuid":"lasdnfa"}
but i have: 但我有:
{user:active, uuid:lasdnfa}
and another thing - i want to add this object to memcache, but before i do this, i have to serialize this object. 还有另一件事-我想将此对象添加到内存缓存,但是在执行此操作之前,我必须序列化此对象。 How i can serialize Json object?
我如何序列化Json对象?
Thanks 谢谢
如果在对象上使用toString()
,则可能需要您的映射器以这种方式输出值:
System.out.println(mapper.writeValueAsString(userInMap)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.