InsideDarkWeb.com

How to fix Exception with queryStringParameters?

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.

Stack Overflow Asked by mvn.2047 on November 22, 2021

1 Answers

One Answer

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

Add your own answers!

Related Questions

WPF prevent combobox selection change under condition

1  Asked on March 8, 2021 by hasan-h

     

How to listen to Boot Complete broadcast in Oneplus?

1  Asked on March 8, 2021 by saarang-tiwari

 

Indirection requires pointer operand error

1  Asked on March 8, 2021 by mr-needhelp

 

Point Cloud Segmentation

1  Asked on March 7, 2021 by aldi-lin

   

Angular HTTP get request is not working in ngOnInit

1  Asked on March 6, 2021 by iamgrooot

   

CheckedChanged not triggering

0  Asked on March 6, 2021

     

flutter splash screen is blurry on physical device

1  Asked on March 5, 2021 by mohamed-mostapha

   

Nginx syslog post request

1  Asked on March 5, 2021 by andreas-hunter

         

Cloning Objects in Google Optimize

0  Asked on March 4, 2021 by jpfotoz

     

Specialize how std::vector grows

3  Asked on March 3, 2021 by gary-allen

   

How to write a range syntax in Peg JS

2  Asked on March 3, 2021 by hemraj-rijal

     

How to randomize two characters in multiple Lines?

4  Asked on March 3, 2021 by malgosh

 

How can I connect to a VPN in docker not using VPN images?

2  Asked on March 2, 2021 by tiago-machado

     

Prevent infinite recursion in c++

4  Asked on March 2, 2021 by joo-menicucci

 

Convert data.frame to time series

1  Asked on March 2, 2021 by davide

       

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.