示例dto生成:
{
"id": 1,
"name": "test",
"attributes": null
}
期望回复:
{
"id": 1,
"name": "test"
}
这里,我必须在返回时忽略属性。我不能在dto中使用@ JsonInclude(JsonInclude.Include.NON_NULL),因为由于其他原因它必须自动生成,并且由于某些情况下它可以为null,因此我不能在模型中提供@NotNull。有人可以帮我吗?
因为属性是一个JSON字段,包括在映射到JSON的以下部分中,它确实起作用了!
objectMapper.setSerializationInclusion(Include.NON_NULL)