SpingBoot-SpringMVC返回json配置JacksonConfig

@Configuration
public class JacksonConfig {
    @Bean
    @Primary
    @ConditionalOnMissingBean
    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        // null值过滤,只对vo起作用 ,map,list不起作用
        objectMapper.setSerializationInclusion(Include.NON_EMPTY);
        // Date类型 返回格式long转为 "yyyy-MM-dd HH:mm:ss"
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        objectMapper.setDateFormat(dateFormat);
        return objectMapper;
    }
}

你可能感兴趣的:(SpingBoot-SpringMVC返回json配置JacksonConfig)