【发布时间】:2023-04-11 02:51:01
【问题描述】:
我想坚持到jsonb类型列(com.vladmihalcea.hibernate.type.json.JsonBinaryType)
@Type(type = "jsonb")
@Column(name = "style", columnDefinition = "jsonb")
private TextStyleJsonB style;
JSON 对象相对较大,我不希望它保存具有空值的字段,所以我决定使用自定义对象映射器,我忽略空值。但它没有应用,所有空值仍然保存到 postgres 数据库。 知道如何摆脱空字段并仅保存具有实际值的字段吗?
在 Spring Boot 中,我有以下应用程序属性
hibernate:
types:
jackson:
object:
mapper: com.xxx.constructor.configurations.CustomObjectMapperSupplier
CustomObjectMapperSupplier 看起来像这样:
public class CustomObjectMapperSupplier
implements ObjectMapperSupplier {
@Override
public ObjectMapper get() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper;
}
}
【问题讨论】:
-
不,和这个问题无关
标签: postgresql spring-boot hibernate jackson jsonb