字段爲(for)null時(hour),保存報錯
Field error in object 'xxx' on field 'xxx': rejected value [null];
原因是(yes)數據庫字段内容爲(for)空,從接口獲取json對象值爲(for)null,重新提交時(hour)格式無法轉換爲(for)對應的(of)類型
方法一(one)
@Configuration
public class JacksonConfig {
@Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
@Override
public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeString("");
}
});
return objectMapper;
}
}
方法二
spring.jackson.default-property-inclusion=NON_NULL
方法三
在(exist)實體類上添加注解
@JsonInclude(JsonInclude.Include.NON_NULL)
- 版權所有:奇站網絡 轉載請注明出(out)處
- 廈門極極網絡科技有限公司,專業提供網站建設,響應式網站建設,小程序開發,系統定制開發。
- 軟件開發咨詢熱線:吳小姐 13313868605