Got error Integer cannot be cast to java.lang.String when trying to get autogenerated id from POST request
See original GitHub issueI am doing automation of REST API using ZeroCode. Created employee using POST request successfully.
In response I have received:
Sceanrio :1 (for “name”: “POST_create_employee”,)
Response:
{
"status" : 200,
"headers" : {
"Date" : [ "Fri, 23 Aug 2019 08:12:06 GMT" ],
"Expires" : [ "0" ],
"Transfer-Encoding" : [ "chunked" ],
"X-XSS-Protection" : [ "1; mode=block" ],
"X-Content-Type-Options" : [ "nosniff" ],
"X-Frame-Options" : [ "SAMEORIGIN" ],
"Content-Type" : [ "application/json;charset=UTF-8" ],
"Cache-Control" : [ "no-store, no-cache, must-revalidate, post-check=0, pre-check=0" ]
},
"body" : {
"httpStatusCode" : null,
"responseCode" : 0,
"responseMessege" : null,
"id" : 123,
"employeeName" : "pTdRexrIij 1566557405261",
"pingBackTime" : 1
}
}
Now, I have to update the created Employee. So I need to send employee id and employee name in PUT request.
{
"name": "PUT_update_employee",
"url": "/employee",
"operation": "PUT",
"request": {
"headers": {
"Authorization": "Bearer eyJhbGciOiJSUzI1NiIsIn",
"userName": "milindwarade"
},
"body": {
"id": "${$.POST_create_employee.response.body.id}",
"employeeName": "${$.POST_create_employee.response.body.employeeName}"
}
},
"assertions": {
"status": 200,
"headers": {
"Date": [
"$NOT.NULL"
],
"Transfer-Encoding": [
"chunked"
],
"Content-Type": [
"application/json;charset=UTF-8"
]
},
"body": {
"httpStatusCode": "OK",
"id": "${$.PUT_update_employee.request.body.id}",
"employeeName": "${$.PUT_update_employee.request.body.employeeName}"
}
}
}
After execution, got an error as -
java.lang.RuntimeException:
JSON:{"headers": {"Authorization": "Bearer eyJhbGciOiJSUzI1NiIsIn","userName": "milindwarade"},"body": {"id": "${$.POST_create_employee.response.body.id}","employeeName": "${$.POST_create_employee.response.body.employeeName}"}}
Possibly comments in the JSON found or bad JSON path found: $.POST_create_employee.response.body.id,
Details: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.jsmart.zerocode.core.engine.preprocessor.ZeroCodeAssertionsProcessorImpl.lambda$1(ZeroCodeAssertionsProcessorImpl.java:150)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at org.jsmart.zerocode.core.engine.preprocessor.ZeroCodeAssertionsProcessorImpl.resolveJsonPaths(ZeroCodeAssertionsProcessorImpl.java:116)
at org.jsmart.zerocode.core.engine.preprocessor.ZeroCodeAssertionsProcessorImpl.resolveStringJson(ZeroCodeAssertionsProcessorImpl.java:87)
Can someone please help to solve/tell me solution for this issue?? Here, id is required to update the employee.
Scenario :2 I have tried with this also (removed <body> from “id”: and “employeeName”: -
{
"name": "PUT_update_employee",
"url": "/employee",
"operation": "PUT",
"request": {
"headers": {
"Authorization": "Bearer eyJhbGciOiJSUzI1NiIsIn",
"userName": "milindwarade"
},
"body": {
"id": "${$.POST_create_employee.response.id}",
"employeeName": "${$.POST_create_employee.response.employeeName}"
}
},
"assertions": {
"status": 200,
"headers": {
"Date": [
"$NOT.NULL"
],
"Transfer-Encoding": [
"chunked"
],
"Content-Type": [
"application/json;charset=UTF-8"
]
},
"body": {
"httpStatusCode": "OK",
"id": "${$.PUT_update_employee.request.id}",
"employeeName": "${$.PUT_update_employee.request.employeeName}"
}
}
}
but then also facing error as -
Possibly comments in the JSON found or bad JSON path found: $.POST_create_employee.response.id,
Details: com.jayway.jsonpath.PathNotFoundException: No results for path: $['POST_create_employee']['response']['id']
at org.jsmart.zerocode.core.engine.preprocessor.ZeroCodeAssertionsProcessorImpl.lambda$1(ZeroCodeAssertionsProcessorImpl.java:150)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at org.jsmart.zerocode.core.engine.preprocessor.ZeroCodeAssertionsProcessorImpl.resolveJsonPaths(ZeroCodeAssertionsProcessorImpl.java:116)
at org.jsmart.zerocode.core.engine.preprocessor.ZeroCodeAssertionsProcessorImpl.resolveStringJson(ZeroCodeAssertionsProcessorImpl.java:87)
Please do needful help. Thanks a lot.
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
java.lang.String cannot be cast to java.lang.Integer in Spring ...
I got error in method searchByRole in menuModelListRole = menuCriteria.list(); . How can i resolve the problem? java · hibernate-criteria.
Read more >java.lang.String cannot be cast to java.lang.Integer
First of all, debug your application and find the line in the code where the error occurs. Just don't expect someone else to...
Read more >Fixing the JPA error "java.lang.String cannot be cast to [Ljava ...
In JPA it's not uncommon to get this error when we work with native queries and we use the createNativeQuery method of the...
Read more >Auto-generated primary keys: UUID, serial or identity column?
This article explores the old question what to use for autogenerated primary keys: UUID, serial or identity column?
Read more >How to fix java.sql.SQLException: Invalid column index ...
Try removing ps.setInt(1) call and reduce subsequent numbers till 4 e.g. ps.setString(2,textField.getText()); should be ps.setString(1,textField.getText());, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @vkjha2000 for quick reply. Please find attached run log for Scenario#1 and Scenario#2. Scenario_1.txt Scenario_2.txt
Waiting for your reply.
Hello @warademilind, we will look into it…
Can you paste your run log with test
CORRELATION-ID
? sample below:--------- TEST-STEP-CORRELATION-ID: 547ca3f6-22c6-42a3-b243-cc4cdc3172c7 ---------
The
time stamp wise log
will help us to figure out the issue better!