In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
When we use MessagePack to serialize List object data, we find that the serialized binary array data is too large.
Please note that this does not happen to all List objects, depending on what is stored in your List object.
For the test source code for this question, please refer to the content in https://github.com/cwiki-us-demo/serialize-deserialize-demo-java/blob/master/src/test/java/com/insight/demo/serialize/MessagePackDataTest.java.
Examine the following code:
List dataList = MockDataUtils.getMessageDataList (600000); ObjectMapper objectMapper = new ObjectMapper (new MessagePackFactory ()); raw = objectMapper.writeValueAsBytes (dataList); FileUtils.byteCountToDisplaySize (raw.length); logger.debug ("Raw Size: [{}]", FileUtils.byteCountToDisplaySize (raw.length))
We will find that the serialized data for the List for this 600000 objects reaches 33MB.
If we add some parameters when defining the ObjectMapper object, we will find that the size will be significantly improved.
Refer to the following code:
List dataList = MockDataUtils.getMessageDataList (600000); ObjectMapper objectMapper = new ObjectMapper (new MessagePackFactory ()); objectMapper.configure (JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); objectMapper.configure (DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.setSerializationInclusion (JsonInclude.Include.NON_NULL); objectMapper.setAnnotationIntrospector (new JsonArrayFormat ()); rawJsonArray = objectMapper.writeValueAsBytes (dataList); logger.debug ("rawJsonArray Size: [{}]", FileUtils.byteCountToDisplaySize (rawJsonArray.length))
If you run the above code, you will see that the output string of the program will be reduced to 23MB.
This is mainly objectMapper.setAnnotationIntrospector (new JsonArrayFormat ()); this sentence works.
In a normal scenario, we can annotate JsonIgnore and add it to the attribute, that is, it will be filtered to the attribute when parsed.
The actual implementation is done by the hasIgnoreMarker in the class JacksonAnnotationIntrospector, which is to determine whether the attribute should be dropped by exclude by reading the annotations. The default AnnotationIntrospector in ObjectMapper is JacksonAnnotationIntrospector, but we can reassign the custom implementation through the method ObjectMapper.setAnnotationIntrospector.
Https://www.cwiki.us/display/Serialization/MessagePack+Jackson+Data+Size
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.