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?

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)