Icon View Incident Report

Serious Serious
Reported By: Doug B
Reported On: 12/2/2015
For: Version 2.03 Build 1
# 4322 TPersistent Class Properties Not Persisted When Class Instance Persisted Using TWriter Instance

The following unit can be used to reproduce a problem I'm having when serializing an object to JSON that contains another nested object.

Here's the output:

{
"field": "field"{
"value": 10,
"description": "description" } }

Here's what I'm expecting.

{
"field": "field",
"Nested": {
"value": 10,
"description": "description" } }

unit TestCase;

interface

uses WebCore;

type
  TNested = class(TPersistent)
    fValue: Integer;
    fDescription: string;
  published
    property Value: Integer read fValue write fValue;
    property Description: string read fDescription write fDescription;
  end;

  TComposite = class(TPersistent)
    fField: string;
    fNested: TNested;
  public
    constructor Create; override;
    destructor Destroy; override;
    function ToJson: string;
  published
    property Field: string read fField write fField;
    property Nested: TNested read fNested write fNested;
  end;

function TestJson: string;

implementation

constructor TComposite.Create;
begin
 inherited Create;
 fNested := TNested.Create;
end;

destructor TComposite.Destroy;
begin
 fNested.Free;
 inherited Destroy;
end;

function TComposite.ToJson: string;
var
 Writer: TWriter;
begin
 Writer := TWriter.Create;
 try
   Writer.Initialize;
   Save(Writer);
   Result := Writer.Output;
 finally
   Writer.Free;
 end;
end;
   
function TestJson: string;
var
 c: TComposite;
begin
 c := TComposite.Create;
 try
   c.Field := 'field';
   c.Nested.Value := 10;
   c.Nested.Description := 'description';
   Result := c.ToJson;
 finally
   c.Free;
 end;
end;

end.



Resolution Resolution
Fixed Problem on 12/3/2015 in version 2.04 build 1


Products Affected Products Affected
Elevate Web Builder
Elevate Web Builder Trial

Image