I have a utility method defined as below.
public static Map<String, Map<String, String>> convertRawMapToStringValues(Map<String, Map<String, Object>> cassandraRowsRawMap) {
Map<String, Map<String, String>> cassandraStrValuesMap = cassandraRowsRawMap.entrySet()
.stream()
.collect(Collectors.toMap(s -> s.getKey(),
s -> s.getValue().entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(),
e -> String.valueOf(e.getValue())))));
return cassandraStrValuesMap;
}
The String.valueOf(e.getValue())
returns a "null" value from the call. I would like to get the null
value for the string.
When I tried the below code, I get an NPE on first .collect
call.
Map<String, Map<String, String>> cassandraStrValuesMap = cassandraRowsRawMap.entrySet()
.stream()
.collect(Collectors.toMap(s -> s.getKey(),
s -> s.getValue().entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(),
e -> e.getValue() == null ? null : String.valueOf(e.getValue())))));
return cassandraStrValuesMap;
}