API methods
Questions related to API methods:
Questions related to API methods:
Note: It is reccomended to read aboutthe technology stack used by the Loymax System. Objects used in the .Net framework are converted from a data structure to a sequence of bytes or a string. This format makes it easier to transfer and store data. The process of converting an object state into a stream of bytes in order to store them in the PC memory, database or file is called serialization. The main purpose of serialization is to save the state of an object so that it can be restored if necessary. The Loymax System uses the Newtonsoft.Json.JsonSerializer for serialization/deserialization. |
|
Let's consider the serialization/deserialization process using an example of how the method works for to get a list of brands
All brands in the System are created using the same template (model), i.e. they are derived from the same data type. The algorithm for obtaining information about brands through API methods works as follows:
| ![]() |
For example, .NET contains Brand1 and BrandBase types (Brand1 is inherited from BrandBase).
public class BrandBase
{
public string Name { get; set; }
public string Description { get; set; }
}
public class Brand1 : BrandBase
{
public string Code { get; set; }
}
Newtonsoft JsonConvert adds the $type property to JSON schema for types during serialization and uses it during deserialization.
Thus, serialization of the Brand1 class instance will create a JSON object with the above mentioned $type property.
Brand1 is an object created using the BrandBase type. Since the serializer expects to get only the object of the BrandBase type, and Brand1 is recognized as a separate type that is inherited from the common BrandBase type, it assigns the $type property to it, which specifies the model according to which the object was created, in order to create an object of the original type during deserialization.
The response to a request to get a list of brands will contain the following information about Brand1:
{
"$type": "Loymax.Api.Models.BrandInfo.Brand1, Loymax.Api",
"name": "Brand1",
"description": "New Brand",
"code": "7878b563333841d79a5e5d14fde29cbe"
}