I hope all is good for you.
I have two maps and I want to keep null values. I know that merge function can’t manage null values but I need to keep null data and use the Binary Operation.
How I can manage my code to avoid NPE.
private Map<String, Object> mergeMaps(
Map<String, Object> map1, Map<String, Object> map2) {
return Stream.of(map1, map2)
.map(Map::entrySet)
.flatMap(Collection::stream)
.collect(
Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(v1, v2) -> StringUtils.isNotEmpty(v1.toString()) ? v1 : v2;
));
}
Thanks a lot.