How can I serialize Jackson's JsonNode object?

蓝咒 提交于 2020-02-02 04:41:06

问题


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?


回答1:


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 does not really need Serializable since it's all raw bytes; although Java clients may try to be helpful and handle serialization.



来源:https://stackoverflow.com/questions/12980892/how-can-i-serialize-jacksons-jsonnode-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!