问题
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