question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Got error Integer cannot be cast to java.lang.String when trying to get autogenerated id from POST request

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
warademilindcommented, Aug 24, 2019

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.

2reactions
vkjha2000commented, Aug 24, 2019

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 ---------

You can strip out your business specific details

The time stamp wise log will help us to figure out the issue better!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found