Control whether TJSONObject.GetElements raises Exception when element not found
Original Reporter info from Mantis: dezlov
-
Reporter name: Denis Kozlov
Original Reporter info from Mantis: dezlov
- Reporter name: Denis Kozlov
Description:
In the latest mainstream version FPC 2.6.0 the JSON functionality has been modified in such a way that breaks existing applications.
TJSONObject.GetElements method is used for retrieving TJSONData by name. Prior to FPC 2.6.0, if the element was not found by the specified name the method would return NIL. In FPC 2.6.0, however, the method raises an Exception when this occurs.
Can I suggest adding an option (property) which will control this new behavior and will allow developers to switch off these exceptions. I understand that we can use IndexOfName method prior to getting the element, but this will require modification of very line of code where JSON elements are being used.
FPC 2.4.2:
----------------------------------------
function TJSONObject.GetElements(AName: string): TJSONData;
begin
Result:=TJSONData(FHash.Find(AName));
end;
----------------------------------------
FPC 2.6.0:
----------------------------------------
function TJSONObject.GetElements(Const AName: string): TJSONData;
begin
Result:=TJSONData(FHash.Find(AName));
If (Result=Nil) then
Raise EJSON.CreateFmt(SErrNonexistentElement,[AName]);
end;
----------------------------------------
Previously working code breaks in 2.6.0:
----------------------------------------
var
J: TJSONObject;
D: TJSONData;
begin
J := TJSONObject.Create;
D := J['dummy'];
if D = nil then
Write('Dummy does not exist...');
else
Write('Found the dummy...');
----------------------------------------
Mantis conversion info:
- Mantis ID: 22273
- Version: 2.6.0
- Monitored by: » dezlov (Denis Kozlov)