jackson序列化时支持空字符串转换为null对象

This commit is contained in:
smallchill 2024-12-10 18:58:55 +08:00
parent 9d7400f381
commit 542413373f
2 changed files with 4 additions and 0 deletions

View File

@ -77,6 +77,8 @@ public class JacksonConfiguration {
objectMapper.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
//日期格式化
objectMapper.registerModule(new BladeJavaTimeModule());
//允许空字符串序列化为null对象
objectMapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
objectMapper.findAndRegisterModules();
return objectMapper;
}

View File

@ -976,6 +976,8 @@ public class JsonUtil {
super.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
//日期格式化
super.registerModule(new BladeJavaTimeModule());
//允许空字符串序列化为null对象
super.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
super.findAndRegisterModules();
}