如何序列化Jackson的JsonNode对象? [英] How can I serialize Jackson's JsonNode object?

查看:106
本文介绍了如何序列化Jackson的JsonNode对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用memcached替换内部缓存系统,但是memcached客户端无法缓存 JsonNode 对象,因为它们没有实现 Serializable
有什么方法可以实现序列化 JsonNode 对象吗?杰克逊是否提供 Serializable 相当于这个类?

I am replacing an in-house caching system with memcached but memcached client cannot cache the JsonNode objects since they don't implement Serializable. Is there any way you can achieve serializing a JsonNode object? Does Jackson provide Serializable equivalent of this class?

推荐答案

JSON是最好的通过将其写为字节来序列化。在Jackson中,它是使用 ObjectMapper 完成的,例如:

JSON is best serialized by writing it out as bytes. In Jackson, it is done using ObjectMapper, for example by:

byte[] raw = objectMapper.writeValueAsBytes(root);

MemCache并不真正需要Serializable,因为它是所有原始字节;虽然Java客户端可能会尝试提供帮助并处理序列化。

MemCache does not really need Serializable since it's all raw bytes; although Java clients may try to be helpful and handle serialization.

这篇关于如何序列化Jackson的JsonNode对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆