The problem I'm facing is that the JSON received is "pure" and has no $type information inside.
If I try using TTMSFNCPersistence.LoadSettingsFromStream I get a ' "$type" property not found in Object descriptor ' error.
If I use the object class helper in WEBLib.TMSFNCTypes I can Create an empty well-formed-with-$type class instance... that stays empty when I'm assigning JSON coming from the REST service above ==> so no reading/parsing is done.
There are various ways to work around this, but one of them is including WEBLib.TMSFNCTypes and use the JSON class helper property.
uses
WEBLib.TMSFNCTypes;
type
TMyObject = class
private
FX: string;
published
property X: string read FX write FX;
end;
procedure TForm1.LoadJSON;
var
o: TMyObject;
begin
o := TMyObject.Create;
o.JSON := '{"X": "Hello"}';
console.log(o.X);
end;
I notice that the JSON is not a 1 on 1 match with the TOpportunity class structure. It really needs to match the JSON structure you see at the right side. Properties will be skipped, if they don't exist, but I see that the JSON data starts with "opportunity". If this is not found, the JSON will be skipped. Also, the property names need to match the name values in the JSON.
I suppose you could try parsing the response JSON, and get the "opportunity" JSON object from the left side JSON data, and then pass this as a JSON string, which will at least be a starting point to match the properties on the right side. Could be possible that you need to take care of case-sensitivity as well.
procedure TfrmDevTest.WebHttpRequest1Response(Sender: TObject; AResponse: string);
var
OP: CAPS.Opportunity.Topportunity;
JT: TJSONObject;
JV: TJSONValue;
begin
WebMemo1.Text := AResponse; // show incoming data - OK
JT := TJSONObject.ParseJSONValue(AResponse) as TJSONObject;
JV := JT.GetValue('opportunity');
WebMemo3.Text := JV.ToString; // show opportunity object extracted - OK
OP := Topportunity.Create;
OP.JSON := JV.ToJSON;
WebMemo2.Text := OP.ToJSON; // still empty... :(
Noted about case-sensitive... I've used https://jsontodelphi.com/ to write a draft of the class from incoming JSON, then manually edited and adjusted the code. Even changing the field and property names exactly matching the case (eg. FId ==> Fid) does not change having an empty result (so far I've not adjusted all the fields, just some). Does order of fields matter ?
To further help you I suppose that we are going to need a sample of some sort. Could you provide your TOpportunity class structure and a sample JSON response? The data can be fake of course. You can send your support question & data to support@tmssoftware.com with a link to this topic.