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

How to use fastjson in springboot to deal with attribute values whose return value is null

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to use fastjson in springboot to deal with the attribute value returned as null". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to use fastjson in springboot to deal with attribute values returned as null".

@ Configurationpublic class WebMvcConfig extends WebMvcConfigurationSupport {public FastJsonHttpMessageConverter fastJsonHttpMessageConverter () {FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter (); FastJsonConfig fastJsonConfig = new FastJsonConfig (); / / todo is configured here, empty and null, and no fastJsonConfig.setSerializerFeatures (SerializerFeature.PrettyFormat) is returned; SerializeConfig serializeConfig = SerializeConfig.globalInstance; serializeConfig.put (LocalDateTime.class, LocalDateTimeSerializer.instance); fastJsonConfig.setSerializeConfig (serializeConfig); List mediaTypeList = new ArrayList (); mediaTypeList.add (MediaType.APPLICATION_JSON_UTF8) MediaTypeList.add (MediaType.APPLICATION_JSON); fastJsonHttpMessageConverter.setSupportedMediaTypes (mediaTypeList); fastJsonHttpMessageConverter.setFastJsonConfig (fastJsonConfig); return fastJsonHttpMessageConverter;}}

This can be configured in the returned information. If there is a null field, the front end will not display this information.

Knowledge point expansion:

Using fastjson in springboot to deal with the attribute value returned as null

Bean public HttpMessageConverters fastJsonHttpMessageConverters () {FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter (); FastJsonConfig fastJsonConfig = new FastJsonConfig (); fastJsonConfig.setSerializerFeatures (SerializerFeature.PrettyFormat); fastJsonConfig.setDateFormat ("yyyy-MM-dd"); fastConverter.setFastJsonConfig (fastJsonConfig); HttpMessageConverter converter = fastConverter; return new HttpMessageConverters (converter);}

You can then use fastjson annotations in the returned DTO, such as

At this point, I believe you have a deeper understanding of "how to use fastjson in springboot to deal with attribute values whose return value is null". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report