0

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?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.