In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about how to deal with JackJson, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
1. Physically
@ JsonInclude (Include.NON_NULL)
/ / place the tag on the attribute, and do not participate in serialization if the attribute is NULL
/ / if you put it on top of the class, it has an effect on all the properties of the class
/ / Include.Include.ALWAYS default
/ / Include.NON_DEFAULT attribute is default and not serialized
/ / the Include.NON_EMPTY attribute is empty ("") or NULL is not serialized.
/ / the Include.NON_NULL attribute is NULL and is not serialized
two。 On the code
ObjectMapper mapper = new ObjectMapper ()
Mapper.setSerializationInclusion (Include.NON_NULL)
/ / set the mapper object through this method, and all serialized objects will be serialized according to the modification rules.
/ / Include.Include.ALWAYS default
/ / Include.NON_DEFAULT attribute is default and not serialized
/ / the Include.NON_EMPTY attribute is empty ("") or NULL is not serialized.
/ / the Include.NON_NULL attribute is NULL and is not serialized
User user = new User (1, ", null)
String outJson = mapper.writeValueAsString (user)
System.out.println (outJson)
3.SerializationFeature.INDENT_OUTPUT: whether to zoom and arrange the output. The default is false. In some cases, the output needs to be scaled and arranged in order to facilitate typesetting and reading.
4. File to Json List example
Private static List parseFromJson (String jsonFileName) {File f = new File ("D:/rule/" + jsonFileName); InputStream inputStream = null; try {inputStream = new FileInputStream (f); JacksonCustomObjectMapper jacksonCustomObjectMapper = new JacksonCustomObjectMapper (); List jsonList = jacksonCustomObjectMapper.readValue (inputStream, new TypeReference () {}); return jsonList;} catch (UnsupportedEncodingException e) {return null;} catch (Exception e) {return null }} above is how to deal with JackJson, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.