@SpringBootApplication
public class DuodianPayApplication {


    public static void main(String[] args) {
        SpringApplication.run(DuodianPayApplication.class, args);
    }

    //在Spring Boot中配置序列化包容性的最简单方法是声明您自己的,适当配置的 Jackson2ObjectMapperBuilder  bean.例如:
    @Bean
    public Jackson2ObjectMapperBuilder objectMapperBuilder() {
        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
        builder.serializationInclusion(JsonInclude.Include.NON_NULL);
        return builder;
    }
    //spring-boot-configuration并放入config:
    @Autowired
    public void configeJackson(Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
        jackson2ObjectMapperBuilder.serializationInclusion(JsonInclude.Include.NON_NULL);
    }
}

参考


asoren
404 声望15 粉丝