admin 管理员组文章数量: 1086019
I have a class which has Include.NON_EMPTY configuration on class level.
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
public class Item extends ExtraInfo {
String id;
List<String> oldAttribute;
}
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ExtraInfo {
@JsonSerialize(using = NewAttributeSerializer.class)
List<BigInteger> newAttribute;
}
I recently implemented a new Serializer NewAttributeSerializer which looks like this:
public class NewAttributeSerializer extends JsonSerializer<List<AnObject>> {
@Override
public void serialize(List<AnObject> objects, JsonGenerator gen, SerializerProvider provider) throws IOException {
List<BigInteger> objIds = objects.stream.filter(AnObject::isEligible).map(AnObject::geId).collect(Collectors.toList())
provider.defaultSerializeValue(objIds, gen);
}
@Override
public boolean isEmpty(SerializerProvider provider, List<AnObject> value) {
return value.isEmpty();
}
Before I implemented this new serializer, I didn't see oldAttribute in response if it had no entries. But now, after implementing this new Serializer, I can see oldAttribute=[] is coming in response if it has empty list. (It should ideally be ignored from final json response because of Include.NON_EMPTY on Item class level.)
So my question is, is there any connection between child class serializer and parent class serializer config?
本文标签:
版权声明:本文标题:spring boot - JsonInclude.Include.NON_EMPTY Doesn't Work after I implemented custom serializer on an attribute - Stack O 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744098619a2533366.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论