Stack Overflow Asked by mvn.2047 on November 22, 2021
I am trying to read GET request parameters:
I have an exception if there are no parameters.
event = objectMapper.readTree(input);
JsonNode queryParameterMap = event.findValue("queryStringParameters");
However, I have no exception if I use "queryParameters" instead of "queryStringParameters".
How could I return null with no exception if there are no parameters?
final String keyParameter = Optional.ofNullable(queryParameterMap)
.map(mapNode -> mapNode.get("my_key").asText())
.orElse(null);
It looks like Exception came from mapping stage.
I have found a solution.
I just added Empty filter
and everything works now.
final String keyParameter = Optional.ofNullable(queryParameterMap)
.filter(s -> !s.isEmpty())
.map(mapNode -> mapNode.get("my_key").asText())
.orElse(null);
Answered by mvn.2047 on November 22, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP