0
votes

How can I handle null objects in array which binds from an inputs? I have

input name=example value=3,4 input name=example value=""

List example = new ArrayList()

the bind result is a list with 3 elements = null ,3, 4 is there an attribute that I can put on the list to ignore this null?

@JsonInclude(Include.NON_NULL) isn't working.

2

2 Answers

0
votes

You can try to send your list to Apache ListUtils:

List result = ListUtils.predicatedList(example, PredicateUtils.notNullPredicate());
0
votes

You can use classic Java 8 Stream API, it will look like this:

list = list.stream()
            .filter(Objects::nonNull)
            .collect(Collectors.toList());