spring boot 空字符串序列化为枚举类,报错解决

配置单独的ObjectMapper,加上属性就可以了,代码如下

    @Bean
    @Primary
    public ObjectMapper objectMapper(){
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
        objectMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL,true);
        objectMapper.setDateFormat(dateConverter);
        return objectMapper;
    }

重点就是:READ_UNKNOWN_ENUM_VALUES_AS_NULL:true

你可能感兴趣的:(SpringBoot,spring)