-
Notifications
You must be signed in to change notification settings - Fork 85
NeonUnwrapped
Paolo Rossi edited this page Feb 3, 2024
·
2 revisions
The NeonUnwrapped
attribute defines values that should be unwrapped/flattened when serialized/deserialized.
Let's see exactly how this works, we'll use the attribute to unwrap the property Name:
TName = class
private
FFirst: string;
FLast: string;
public
property First: string read FFirst write FFirst;
property Last: string read FLast write FLast;
end;
TPerson = class
private
FAge: Integer;
FName: TName;
public
property Age: Integer read FAge write FAge;
property Name: TName read FName write FName;
end;
Produces
{
"Age": 50,
"Name": {
"First": "Paolo",
"Last": "Rossi"
}
}
Now, using the NeonUnwrapped
annotation
TPerson = class
private
FAge: Integer;
FName: TName;
public
property Age: Integer read FAge write FAge;
[NeonUnwrapped]
property Name: TName read FName write FName;
end;
Produces:
{
"Age": 50,
"First": "Paolo",
"Last": "Rossi"
}
The NeonUnwrapped
can only be added to properties, and not classes, as it is contextual, also this attribute applies only to objects/records not simple values and arrays.
Neon Libray • Project Home • paolo's Repositories