For a solution I have "borrowed" heavily from
kaufmann on how to extract values from json.
For the modifications inside NAV (11.0.21441) everything has worked like a charm. Now the customer wants to upgrade, and we want to go full on extensions this time. However now the code is failing due to an ambigouos call when when using for instance DateTime. Does anybody know how I can restructure the code so that is could work again in 14.0.32615?
procedure GetValueAsDateTime(JObject: DotNet MyJObject; PropertyName: Text) ReturnValue: DateTime
var
DotNetDateTime: DotNet MyDateTime; //Defined in the dotnet.al file
CultureInfo: DotNet MyCultureInfo; //Not really neccesary here, but kept since it is in the original code
begin
DotNetDateTime := JObject.GetValue(PropertyName).ToObject(GETDOTNETTYPE(DotNetDateTime));
ReturnValue := DotNetDateTime;
end;
For the various other places in the code where it says DotNetBoolean.Parse(JObject.GetValue(PropertyName).ToString); it works fine, but for the .ToObject I am now getting an error "The call is ambiguous between the following methods or properties: 'ToObject(DotNet "Newtonsoft.Json.JsonSerializer")' and 'ToObject(DotNet "System.Type")'AL(AL0196)"
I can propably get it to work using the ToString, and then evaluating it. But I would prefer to get the correct type straight away. Please advice.
Answers
assembly("mscorlib")
{
Version = '4.0.0.0';
Culture = 'neutral';
PublicKeyToken = 'b77a5c561934e089';
type("System.DateTime"; MyDateTime { }
}
assembly("Newtonsoft.Json")
{
Version = '4.5.0.0';
Culture = 'neutral';
PublicKeyToken = '30ad4fe6b2a6aeed';
type("Newtonsoft.Json.Linq.JToken"; MyJToken) { }
type("Newtonsoft.Json.Linq.JObject"; MyJObject) { }
}