MessagePackJavaJacksonDataformat在Map中不使用Str
当你希望在 Map 中不使用 String 为 Key,那么你需要使用 MessagePackKeySerializer
来为 key 进行序列化。
创新互联公司2013年成立,先为高港等服务建站,高港等地企业,进行企业商务咨询服务。为高港企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
本测试方法,可以在 https://github.com/cwiki-us-demo/serialize-deserialize-demo-java/blob/master/src/test/java/com/insight/demo/serialize/MessagePackSerializer.java 中找到。
/** * testMessagePackSerializationMapKey */ @Test @JsonSerialize(keyUsing = MessagePackKeySerializer.class) public void testMessagePackSerializationMapKey() { logger.debug("testMessagePackSerializationNotCloseInputStream"); byte[] bytes = new byte[0]; Integer uuid_a = 101; Integer uuid_b = 102; // Instantiate ObjectMapper for MessagePack ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); Mapmap = new HashMap<>(); MessageData messageData = new MessageData(); // Element A 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
https://www.cwiki.us/display/Serialization/MessagePack+Jackson+Dataformat
网站栏目:MessagePackJavaJacksonDataformat在Map中不使用Str
URL链接:http://hbruida.cn/article/jiojee.html