Cannot coerce value into type: inteface java.util.map

I'm passing parameters into a named query. I'm getting this error on the gateway logs.

Gateway log extract (with line breaks for ease of reading)
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source) at java.base/java.lang.reflect.Method.invoke (Unknown Source) java.lang.ClassCastException:
jJava.lang.ClassCastException:
Cannot coerce value '[{
	'Panel_type': u'ROBOT',
	'Description': u'',
	'Switch_name': u'ABCDEFG',
	'Panel_id': u' ',
	'Asset_type': u'General IoT abc',
	'VLAN': u'210',
	'Edited_by': u'bloggs_joe',
	'Device_type': u' ',
	'Edit_date’: Sun Sep 14 19:17:18 BST 2025,
	'Manufacturer': u'Myopic',
	'Asset_name': u'\\J45',
	'MAC address’: u'00:01:02:E7:D6:FA',
	'Notes': u'Notes test. ',
	'Drawing_number': u'DWG-1039',
	'Floor': u'20.5m',
	'Patch_port': u'85',
	'Port_num': u'Gi1/2/34',
	'Panel_drawing_ref': u'',
	'Serial_number': u'N/A',
	'Equipment_type': u'Case maker',
	'Process_type': u'Forming',
	'Model': u'Superior 11',
	'Id': 20,
	'IP_integer': OL,
	'IP_integer_legacy': OL,
	'Location’: u'East Fab'
}]' 
into type: interface java.util.Map

(I've edited any sensitive text strings. There are three integer columns in the database: Id, IP_integer and IP_integer_legacy.)

Can anyone spot a blunder?
Thanks!

Looks like you've passed a list containing a dictionary and not a dictionary.

There’s a lot of mismatched backticks, single quotes and double quotes, if you clean them up does it still error?

I noticed that too, but the code is,

parameters = {'Id':  ..... }
system.db.runNamedQuery(project, query, parameters)

I'm definitely passing a dictionary - or trying!

Oops. I'm working through a jump server onto a machine with no Internet connection and no clipboard cut'n'paste. I used OCR to convert a screengrab for my post. It has randomised the types of backticks and I didn't notice. In the error message there are only standard apostrophes. I'll fix up my original post.
Thanks for the eyes!

Cleanup done. :broom:

There’s a random Pipe character just before patch port.

Another missed OCR artifact. Fixed, thanks.

Is it normal for the timestamp to not be a n escaped string in the readback?

I had wondered about the date format. (What's an "n escaped string"?) The date parameter is generated by

parameters = {..., "Edit_date": system.date.now(), ...}

and the error message returns,
'Edit_date’: Sun Sep 14 19:17:18 BST 2025

I think that is correct as long as the parameter in the named query is expecting a timestamp not a string. When errors print to logs they assert .toString() from memory.

Hmm!
The named query (Query type: Update query) is expecting Edit_date / DateTime parameter.
The MS SQL database column is datetime2 which should handle it.

parameters = {
	"Panel_type": u'ROBOT',
	'Description': u'',
	'Switch_name': u'ABCDEFG',
	'Panel_id': u' ',
	'Asset_type': u'General IoT abc',
	'VLAN': u'210',
	'Edited_by': u'bloggs_joe',
	'Device_type': u' ',
	'Edit_date': system.date.now(),
	'Manufacturer': u'Myopic',
	'Asset_name': u'\\J45',
	'MAC address': u'00:01:02:E7:D6:FA',
	'Notes': u'Notes test. ',
	'Drawing_number': u'DWG-1039',
	'Floor': u'20.5m',
	'Patch_port': u'85',
	'Port_num': u'Gi1/2/34',
	'Panel_drawing_ref': u'',
	'Serial_number': u'N/A',
	'Equipment_type': u'Case maker',
	'Process_type': u'Forming',
	'Model': u'Superior 11',
	'Id': 20,
	'IP_integer': 0L,
	'IP_integer_legacy': 0L,
	'Location': u'East Fab'
}
results = system.db.runNamedQuery("test",parameters=parameters)

I can run that code above with no errors in my docker test gateway.

I think I found the problem. I've fallen victim to the project name syntax trap.
results = system.db.runNamedQuery("PROJECTNAME", "test",parameters=parameters)
Phil has commented on this in several posts and pointed out that it is odd in that the projected name should be after the named query and parameters rather than first in the list.

I was using the gateway scope syntax. I've removed the project name from the function and it seems to work. It's midnight here. Time for sleep. I'll continue debugging tomorrow.

Thank you very much for taking the time to try it out.

1 Like

It is fixed in the replacement system.db.exec*() functions in v8.3.

1 Like