jackson-databind
jackson-databind copied to clipboard
`JsonFormat(shape=Shape.ARRAY)` does not consider `Include.NON_NULL`
@JsonPropertyOrder({"a", "b"})
@JsonFormat(shape = JsonFormat.Shape.ARRAY, with = Feature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
public class MyDTO {
private final String a;
@JsonInclude(Include.NON_NULL)
private final String b;
}
When serialising the above class when b is null, b is still present inside the array
Expected a="hello" b = null. [a:"hello"] Actual [a:"hello", b:"null"]
[Wrong repo, will move to jackson-databind]
Since Array-shape notation must have values for all columns (placeholder if nothing else), there must always be a value, even if placeholder, to keep indexes (this would mostly matter for columns "in the middle", but dropping last columns could be problematic as well -- and would require additional logic to determine at any rate).
I guess in theory it would be possible to then use null
but the way things work is that inclusion filtering does not apply to this notation.
So I think I will considered this working as designed. Would be good to improve documentation to indicate that filtering does not apply for Array-based POJO serialization.