Gorilla.Arena.JSONWrap Unit Reference
Overview
The Gorilla.Arena.JSONWrap unit provides TJSONWrapObject, the JSON backed
object entities are built on. Instead of fields, an
instance holds a TJSONObject and reads and writes its properties through it,
using RTTI to convert between TValue and JSON.
That is what makes an entity serialisable without any per-class code: the document is already the wire format.
The interfaces are declared separately in Gorilla.Arena.Intf.JSONWrap, so a
unit can depend on the contract without depending on the implementation.
Class Hierarchy
TInterfacedObject
└── TJSONWrapObject implements IJSONWrapObject
├── TJSONWrapError implements IJSONWrapError
└── TGorillaArenaEntity
TJSONWrapObjectClass = class of TJSONWrapObject
TJSONWrapErrorClass = class of TJSONWrapError
Types (Gorilla.Arena.Intf.JSONWrap)
| Type | Description |
|---|---|
TJSONWrapObjectList |
TList<IJSONWrapObject> |
TJSONWrapArray |
TArray<TValue> |
GFloatFormat |
Global TFormatSettings, fixed to en-US so numbers travel between locales |
IJSONWrapObject
GUID {E51FDEE9-E41C-4498-B66D-B33B33F975F6}
| Method | Description |
|---|---|
GetRefCount() : Integer |
Current reference count |
ToString() : String |
The document, serialised |
ToJSON() : TJSONValue |
The document. The caller owns the result |
ApplyFromJSON(const AData : TJSONObject) |
Replaces the document |
GetPropertyType(const pName : String) : TClass |
The class behind a property, when it has one |
GetJSONProperty(const pName : String) : TValue |
Reads one property |
SetJSONProperty(const pName : String; const pValue : TValue) |
Writes one property |
GetListProperty(const pName : String; const pClass : TClass; const AMultipleTypes : Boolean = false) : TJSONWrapObjectList |
Reads an array of objects |
GetIntfProperty(const pName : String; const pClass : TClass) : IJSONWrapObject |
Reads a nested object |
GetArrayProperty(const pName : String) : TJSONWrapArray |
Reads an array of plain values |
IJSONWrapError (GUID {30EC6018-0B1F-4801-A7B7-2A674D519D6E}) descends it
and marks an object that carries an error rather than data.
TJSONWrapObject
Public Properties
| Property | Type | Description |
|---|---|---|
Origin |
Boolean |
True when this instance owns its document and frees it. False for a view onto somebody else's |
Class Members
| Member | Description |
|---|---|
class var error_class : TJSONWrapErrorClass |
Which class to build for an error object |
class function ValueToJSON(const AValue : TValue) : TJSONValue |
Converts a TValue to JSON |
class function FromJSON(const AData : TJSONObject) : IJSONWrapObject |
Builds an instance from a document |
class function FromJSON(const AData : String) : IJSONWrapObject |
The same from text |
Type Mapping
GetRttiValue reads JSON back into a TValue:
| JSON | Delphi |
|---|---|
true / false |
Boolean |
| number with a decimal point | Double |
| number without one | Integer |
| array | TJSONWrapArray |
| object | nested wrap object |
| anything else | String |
A number is therefore typed by how it was written: 1 comes back as
Integer, 1.0 as Double. Where that matters, write the value with a
decimal point, or convert explicitly on the way out.
TJSONWrapError
| Method | Description |
|---|---|
class IsErrorObject(const AJSON : TJSONValue) : Boolean |
Whether a document is an error rather than data |
class GetErrorMessage(const ACode : Integer) : String |
Text for an error code |
Both are virtual — a descendant defines what an error looks like for its own
protocol.