msgpack-java
msgpack-java copied to clipboard
Convert from org.json.JSONObject.
How can I convert org.json.JSONObject from android to message pack? My object is nested multiple times.
com.fasterxml.jackson.databind.ObjectMapper can serialize org.json.JSONObject. So you can convert org.json.JSONObject instances to MessagePack format like this
JSONObject root = new JSONObject();
:
ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
byte[] bytes = objectMapper.writeValueAsBytes(root);
// ^^^ `bytes` is MessagePack serialized data.
@komamitsu thank you.
@komamitsu Hello! Thank you for your answer. It helped! I have only one problem: when try to recreate the initial JSONObject it has two extra nested JSONObjects. Could you help me with an advice?How can I avoid the creation of these objects?