Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-01 01:08:58 09月21日 Update

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!

Tags: Properties processing information content learning configuration practical deeper middle use interest front end field practicality practical simple operation method time more friends comments Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL Shulou Technology Huawei MariaDB