Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
casting of js.executeAsyncScript output to Map<String,String>

I want to cast the output of below script into Map<string,string> but it is showing "java.lang.String cannot be cast to java.util.Map"error. How can we cast that in map??

final JavascriptExecutor js = (JavascriptExecutor) driver;
            Map<String,String> str = new HashMap<>();
            str = (Map<String, String>) js.executeAsyncScript("var myHeaders = new Headers();\n" +
                    "myHeaders.append('client-id', 'LPDP');\n" 
                    "let inputEntities = new Map();\n" +
                    "inputEntities.set(\"Commons$customerId\", \"\\\"A2ZLDCQRXMMNLG\\\"\")\n" +
                    "inputEntities.set(\"Commons$marketPlaceId\", \"\\\"A2XZLSVIQ0F4JT\\\" +
                    "let entitiesToBeResolved = [\"Rewards$APPA$GetAllPromotions$applicablePromotionDetailList\"]\n" +
                    "\n" +
                    "const executeInput = {\n" +
                    "\"inputEntities\": Object.fromEntries(inputEntities),\n" +
                    "\"entitiesToBeResolved\": entitiesToBeResolved,\n" +
                    "};\n" +
                    "var obj \n" +
                    "\n" +
                    "fetch(\"url", {\n" +
                    "  method: 'POST',\n" +
                    "  headers: myHeaders,\n" +
                    "  body: JSON.stringify(executeInput),\n" +
                    "})\n" +
                    "  .then(response => response.text())\n" +
                    "  .then(arguments[0])\n" +
                    "    .then(result => obj = result);\n" +
                    "\n" +
                    "  return obj;");
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I assume your response is in Json format. You can use Gson to convert the String to Map.

import com.google.gson.Gson;

Map<String, String> str = new HashMap<String, String>();
String response = js.executeAsyncScript("....");
str = new Gson().fromJson(response, HashMap.class);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!