Hi guys,
I am working on creating an application that will integrate with QuickFile.
This application is a batch app that requires to determine exactly one client to perform actions on. To do so I send a ClientSearch message to the JSON endpoint. I get back a response message (BTW it took me some headache to get the asymmetric “payload” vs. “Client_Search” rendering handled correctly).
However, the response message is inconsistently rendered depending on the number of client entries were found.
If the system found several clients, I get back something like this (abbreviated, and sensitive info obfuscated):
{
"Client_Search": {
"Header": {
"MessageType": "Response",
"SubmissionNumber": "..."
},
"Body": {
"RecordsetCount": "3",
"ReturnCount": "3",
"Record": [
{
"ClientID": "****",
"ClientCreatedDate": "25/05/2017",
"CompanyName": "*****",
...
},
{
"ClientID": "****",
"ClientCreatedDate": "25/05/2017",
"CompanyName": "*****",
...
},
{
"ClientID": "****",
"ClientCreatedDate": "25/05/2017",
"CompanyName": "*****",
...
}
]
}
}
}
If I change the search parameters to get only one result, I get this:
{
"Client_Search": {
"Header": {
"MessageType": "Response",
"SubmissionNumber": "..."
},
"Body": {
"RecordsetCount": "1",
"ReturnCount": "1",
"Record": {
"ClientID": "****",
"ClientCreatedDate": "25/05/2017",
"CompanyName": "*****",
...
}
}
}
}
However, according to json.org the response should be formatted like this for a 1-value array:
{
"Client_Search": {
"Header": {
"MessageType": "Response",
"SubmissionNumber": "..."
},
"Body": {
"RecordsetCount": "3",
"ReturnCount": "3",
"Record": [
{
"ClientID": "****",
"ClientCreatedDate": "25/05/2017",
"CompanyName": "*****",
...
}
]
}
}
}
and for a 0-value 1-value array:
{
"Client_Search": {
"Header": {
"MessageType": "Response",
"SubmissionNumber": "..."
},
"Body": {
"RecordsetCount": "3",
"ReturnCount": "3",
"Record": [
]
}
}
}
I am using Java 1.8 with Apache Commons Http Client, and GSON (Google’s Java Json library). GSON appears to be very picky, and very rightfully so since www.json.org defines arrays as follows:
array
[]
[ elements ]
elements
value
value , elements
In other words, an array always includes brackets!
Consequently, I get the following stacktrace exception:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 170
Thanks,
Michel