I got this error when i was trying to invoke an sql query through a DataService .
The studenttest-1.0.0.dbs service, which is not valid, caused {1} DS Fault Message: A JSON Array cannot be contained in the result records
DS Code: UNKNOWN_ERROR
This is the Object to be returned from the DataService
<sql>SELECT * from etudiant where nom =?</sql>
<param name="nom" sqlType="STRING" />
<result outputType="json">
{
"Envelope": {
"Body": {
"GetFacturesClientResponse": {
"GetFacturesClientResult": {
"code": 0,
"nbreFactures": 2,
"totalResteAPayerFactures": 67.832,
"listeFactures": {
"Facture": [
{
"id":"$id",
"nom":"$nom",
"prenom":"$prenom",
"age":"$age",
"note":"$note"
}
]
},
"codeClient": "P-2008-043681",
"nom": "Oussama",
"prenom": "Haythem"
}
}
}
}
}
</result>
</query>```
CodePudding user response:
You can't add complex JSON structures to the result mapping, you need to adhere to the following format. Read more here.
Also, the structure of the JSON template should follow some guidelines in order to be compatible with the result. These guidelines are:
- The top most item should be a JSON object. It cannot be a JSON array.
- For handling multiple records from the result set, the immediate child of the top most object can be a JSON array, and the array should contain only a single object.
- If only a single result is returned, the immediate child of the top most object can be a single JSON object.
- After the immediate child of the top most object, there cannot be other JSON arrays in the mapping.
Hence try a simple mapping like below and add the rest of the JSON in the integration layer. (Interface the Dataservice with another API and modify the JSON structure within the API before responding to the client)
{
"listeFactures": {
"Facture": [
{
"id":"$id",
"nom":"$nom",
"prenom":"$prenom",
"age":"$age",
"note":"$note"
}
]
}
}