Breeding calculation Java

2022-12-21   ES  

SpringBoot Return to the JSON data on the page. If there is a data null, return the empty string.

SpringBoot uses Jackson to resolve JSON data.

Let’s do the configuration:

Package com.yhcode.config; 

 Import com.fasterxml.jackson.core.jsongnerator; 
 Import com.fasterxml.jackson.databind.jsonserializer; 
 Import com.fasterxml.jackson.dataBind.objectMapper; 
 Import com.fasterxml.jackson.databind.serializerProvider; 
 Import org.SpringFramework.Boot.autoConfigure.Condition.ConditionalonMissingBean; 
 Import org.springframework.context.annotation.bean; 
 Import org.springframework.context.annotation.configuration; 
 Import org.springframework.context.annotation.primary; 
 Import org.Springframework.http.converter.json.jackson2ObjectMapperbuilder; 


  * Process Null value returned by Jackson 
 Public Class JacksonConfig { 

     @ConditionalonMissingBean (ObjectMapper.Class) 
     Public ObjectMapper JacksonObjectMapper (Jackson2ObjectMapperBuilder Builder) { 
         ObjectMapper objectMapper = Builder.createxmlMapper (false) .build (); 
         objectMapper.getSerializerProvider (). SetnullValueSerializer (New JSONSERIALIZER <object> () {{ 
             Public Void Serialize (Object O, JSONGENARTOR JSONGENATOR, SerializerProvider Serprovider) Throws IOEXception { 
                 jsongenerator.writeString (""); 
         Return objectmapper; 

This can turn the NULL value back to JSON into an empty string.


Related Posts

Unity with (6) Use Camera.setReplacementShader to achieve a simple scene killing effect

python2.7 and 3.5 dual versions coexist and the use of PIP

About the Input box defaultValue in Antd-Desgin-Vue

Matplotlib The difference between Matshow and imshow in Matplotlib

Breeding calculation Java

Random Posts

Ural Sightseeing Trip

HDU 6053 Reversing DP or Mobius Reverse

docker installation and fast entry (Mac) BUPT

solve the problem of pyinstall in Python3.7.2

pycharm background replacement