0

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.

  • See https://stackoverflow.com/questions/6433478/is-there-a-standard-java-list-implementation-that-doesnt-allow-adding-null-to-i – Ori Marko Jan 23 '19 at 07:45

2 Answers2

0

You can try to send your list to Apache ListUtils:

List result = ListUtils.predicatedList(example, PredicateUtils.notNullPredicate());
smoczyna
  • 489
  • 6
  • 18
0

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

list = list.stream()
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
Artur Vakhrameev
  • 794
  • 7
  • 11