{"action":"created","issue":{"url":"https://api.github.com/repos/danieleteti/delphimvcframework/issues/157","repository_url":"https://api.github.com/repos/danieleteti/delphimvcframework","labels_url":"https://api.github.com/repos/danieleteti/delphimvcframework/issues/157/labels{/name}","comments_url":"https://api.github.com/repos/danieleteti/delphimvcframework/issues/157/comments","events_url":"https://api.github.com/repos/danieleteti/delphimvcframework/issues/157/events","html_url":"https://github.com/danieleteti/delphimvcframework/issues/157","id":366362008,"node_id":"MDU6SXNzdWUzNjYzNjIwMDg=","number":157,"title":"Error on TMVCJsonDataObjectsSerializer.DeserializeDataSetRecord","user":{"login":"Ravaut123","id":1968086,"node_id":"MDQ6VXNlcjE5NjgwODY=","avatar_url":"https://avatars3.githubusercontent.com/u/1968086?v=4","gravatar_id":"","url":"https://api.github.com/users/Ravaut123","html_url":"https://github.com/Ravaut123","followers_url":"https://api.github.com/users/Ravaut123/followers","following_url":"https://api.github.com/users/Ravaut123/following{/other_user}","gists_url":"https://api.github.com/users/Ravaut123/gists{/gist_id}","starred_url":"https://api.github.com/users/Ravaut123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ravaut123/subscriptions","organizations_url":"https://api.github.com/users/Ravaut123/orgs","repos_url":"https://api.github.com/users/Ravaut123/repos","events_url":"https://api.github.com/users/Ravaut123/events{/privacy}","received_events_url":"https://api.github.com/users/Ravaut123/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-03T14:16:05Z","updated_at":"2018-10-23T21:56:19Z","closed_at":null,"author_association":"NONE","body":"We can have a Invalid class typecast in DeserializeDataSetRecord.\r\n\r\n```\r\nprocedure TMVCJsonDataObjectsSerializer.DeserializeDataSetRecord(\r\n  const ASerializedDataSetRecord: string;\r\n  const ADataSet: TDataSet;\r\n  const AIgnoredFields: TMVCIgnoredList;\r\n  const ANameCase: TMVCNameCase);\r\nvar\r\n  JsonObject: TJsonObject;\r\nbegin\r\n  if (ASerializedDataSetRecord = EmptyStr) or (not Assigned(ADataSet)) then\r\n    Exit;\r\n\r\n  JsonObject := TJsonObject.Parse(ASerializedDataSetRecord) as TJsonObject;  // --> ERROR: result can be TJsonArray\r\n  try\r\n    ADataSet.Edit;\r\n    JsonObjectToDataSet(JsonObject, ADataSet, AIgnoredFields, ANameCase);\r\n    ADataSet.Post;\r\n  finally\r\n    JsonObject.Free;\r\n  end;\r\nend;\r\n```\r\n\r\nJsonObject := TJsonObject.Parse(ASerializedDataSetRecord) as TJsonObject; \r\nIf the parse return a TJsonArray we get an error and then we have memoryleaks.\r\n\r\nChange the code like this\r\n\r\n```\r\nprocedure TMVCJsonDataObjectsSerializer.DeserializeDataSetRecord(\r\n  const ASerializedDataSetRecord: string;\r\n  const ADataSet: TDataSet;\r\n  const AIgnoredFields: TMVCIgnoredList;\r\n  const ANameCase: TMVCNameCase);\r\nvar\r\n  JsonBase: TJsonBaseObject;\r\nbegin\r\n  if (ASerializedDataSetRecord = EmptyStr) or (not Assigned(ADataSet)) then\r\n    Exit;\r\n\r\n  JsonBase := TJsonObject.Parse(ASerializedDataSetRecord);\r\n  try\r\n    if JsonBase is TJsonObject then\r\n    begin\r\n      ADataSet.Edit;\r\n      JsonObjectToDataSet(JsonBase as TJsonObject, ADataSet, AIgnoredFields, ANameCase);\r\n      ADataSet.Post;\r\n    end\r\n    else\r\n      raise EMVCSerializationException.Create\r\n            ('Cannot deserialize, the serializer does not have a valid TJsonObject type.');\r\n  finally\r\n    JsonBase.Free;\r\n  end;\r\nend;\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/danieleteti/delphimvcframework/issues/comments/432435959","html_url":"https://github.com/danieleteti/delphimvcframework/issues/157#issuecomment-432435959","issue_url":"https://api.github.com/repos/danieleteti/delphimvcframework/issues/157","id":432435959,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMjQzNTk1OQ==","user":{"login":"danieleteti","id":1428644,"node_id":"MDQ6VXNlcjE0Mjg2NDQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1428644?v=4","gravatar_id":"","url":"https://api.github.com/users/danieleteti","html_url":"https://github.com/danieleteti","followers_url":"https://api.github.com/users/danieleteti/followers","following_url":"https://api.github.com/users/danieleteti/following{/other_user}","gists_url":"https://api.github.com/users/danieleteti/gists{/gist_id}","starred_url":"https://api.github.com/users/danieleteti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieleteti/subscriptions","organizations_url":"https://api.github.com/users/danieleteti/orgs","repos_url":"https://api.github.com/users/danieleteti/repos","events_url":"https://api.github.com/users/danieleteti/events{/privacy}","received_events_url":"https://api.github.com/users/danieleteti/received_events","type":"User","site_admin":false},"created_at":"2018-10-23T21:56:19Z","updated_at":"2018-10-23T21:56:19Z","author_association":"OWNER","body":"Thank you for your contribution. Do you have a reproducible real case? When the problem happens?"}}
{"actor":{"display_login":"danieleteti"}}