增加一个配置解决:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MyJsonConfig {
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}
}
666666666666666666666!!
本文介绍了一种Spring配置方式,通过禁用序列化特性,防止在序列化空Bean时抛出异常。具体操作是在配置类中使用@Bean注解创建ObjectMapper实例,并调用其disable方法,参数为SerializationFeature.FAIL_ON_EMPTY_BEANS。
6301

被折叠的 条评论
为什么被折叠?



