Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Serialization and deserialization of MessagePack Java Jackson Dataformat-Map

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

This test method can be found in https://github.com/cwiki-us-demo/serialize-deserialize-demo-java/blob/master/src/test/java/com/insight/demo/serialize/MessagePackSerializer.java.

We need to define the MAP required for testing, and the method of defining Map can be found in the test program below.

/ * SerializationMap * / @ Test public void testMessagePackSerializationMap () {byte [] bytes = new byte [0]; String uuid_a = UUID.randomUUID () .toString (); String uuid_b = UUID.randomUUID () .toString (); / / Instantiate ObjectMapper for MessagePack ObjectMapper objectMapper = new ObjectMapper (new MessagePackFactory ()); Map map = new HashMap (); MessageData messageData = new MessageData () / / Element An in MAP messageData.setUuid (UUID.randomUUID (). ToString ()); messageData.setName ("CWIKI.US-A"); map.put (uuid_a, messageData); / / Element B in MAP messageData = new MessageData (); messageData.setUuid (UUID.randomUUID (). ToString ()); messageData.setName ("CWIKI.US-B"); map.put (uuid_b, messageData) Try {/ / Serialize a Java object to byte array bytes = objectMapper.writeValueAsBytes (map); logger.debug ("Length of Bytes: [{}]", bytes.length); / / Deserialize the byte array to a MAP Map deserialized = objectMapper.readValue (bytes, new TypeReference () {}); logger.debug ("Deserialized MAP Count: [{}]", deserialized.size ()) Logger.debug ("MAP index 0: [{}]", deserialized.get (uuid_a). GetName ()); assertEquals ("CWIKI.US-A", deserialized.get (uuid_a). GetName ());} catch (JsonProcessingException ex) {logger.error ("Serialize Error", ex);} catch (IOException e) {e.printStackTrace ();}

Https://www.cwiki.us/display/Serialization/MessagePack+Jackson+Dataformat

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report