I have no idea why (yet) but this is what my chromium browser returns in the console:
Uncaught
fMessage: "Field definition 9 in has no or invalid name property"
Perhaps you have an idea about the fieldname ?. I will look through the code and see if I am able to track that down but I do not have many time left for today.
Got it, I think
Inside restdata.pp, line 58 (here 11 highlighted):
MetaData.Arrays['fields'].Add(TJSONObject.Create(
['supplier',
'product',
'type',
'size',
'reference',
'package',
'quantity',
'pkquantity',
'location',
'int']));
I was thrown off by the error message only mentioning "in', and not "int"
I have not been able to test further yet.
edit: ok, I can see you got your queue from the demo and I noticed on the first testruns (scroll down to highlighted):
{
"metaData" : {
"fields" : [
{
"name" : "supplier",
"type" : "string"
},
{
"name" : "product",
"type" : "string"
},
{
"name" : "type",
"type" : "string"
},
{
"name" : "size",
"type" : "string"
},
{
"name" : "reference",
"type" : "string"
},
{
"name" : "package",
"type" : "string"
},
{
"name" : "quantity",
"type" : "int"
},
{
"name" : "pkquantity",
"type" : "string"
},
{
"name" : "location",
"type" : "string"
},
{
"supplier" : "product",
"type" : "size",
"reference" : "package",
"quantity" : "pkquantity",
"location" : "int"
}
],
"root" : "Data"
},
"Data" :
Which currently doesn't make any sense to me. Why is it there, inside the JSON (metadata) and as a field-def ?
When I removed the int, I got an exception (missing pair value):
An unhandled exception occurred at $000D7558:
EJSON: TJSONObject must be constructed with name,value pairs
$000D7558 TJSONDATA__DOERROR, line 1382 of ./fcl-json/src/fpjson.pp
$000DBF28 TJSONOBJECT__CREATE, line 3200 of ./fcl-json/src/fpjson.pp
$0007C0C4 LOADRESTDATA, line 57 of restdata.pp
$0007D0DC RESTDATA_$$_init$, line 239 of restdata.pp
$00032E70 fpc_initializeunits, line 969 of /home/Pierre/pas/release-build/release_3_2_0/fpcsrc/rtl/inc/system.in
which makes sense as fielddefs come in pairs, and those do not look like field-definitions to me. Unless I'm missing something that I am not aware off with regards to TRestDataSet, otherwise this seems to be your (current) issue.
edit2: in the restserver example, it seems that the original (stored on disk) data is extended (before sending to the client) with an extra field with the name "id" of type "int". That is why the restserver example seems to be 'fixing' all the data by adding an id field using the following loop:
MetaData.Arrays['fields'].Add(TJSONObject.Create(['name','id','type','int']));
For I:=0 to Data.Count-1 do
Data.Objects[i].Add('id',I+1);
LastID:=Data.Count;
.. which makes sense if you actually make use of such an id. However as you can see from your own code, you seem to be doing (or wanting) something else there ?