import cn.hutool.json.JSONNull; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import org.springframework.boot.jackson.JsonComponent; import java.io.IOException; @JsonComponent public class JsonNullSerializer extends JsonSerializer<JSONNull> { @Override public void serialize(JSONNull jsonNull, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeNull(); } }
一般出现错误或异常的提示为:
No serializer found for class cn.hutool.json.JSONNull and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
上面的解决办法就是通过新建一个专门针对JSONNull进行序列化的类,用来处理null的问题。
标签:Map,null,jackson,hutool,报错,JSONNull,import,序列化 From: https://www.cnblogs.com/dj258/p/18685808