API methods
Questions related to the work of API methods:
Questions related to the work of API methods:
Note: It is reccomended to read aboutthe technology stack used by the Loymax system. Objects used in the .Net framework are translated from a data structure to a sequence of bytes or a string. In this format it is convenient to transfer and store data. The process of translating an object state into a stream of bytes in order to store them in PC memory, a database or a file is called serialization. The main purpose of serialization is to save the state of an object so that it is possible to restore it if necessary. The Loymax system uses the Newtonsoft.Json.JsonSerializer for serialization/deserialization. |
Let's take the serialization/deserialization process as an example of how the method works for receiving a list of brands
All brands in the System are created using the same template (model), that is, they are inherited from the same data type. The algorithm for obtaining information about brands through API methods works as follows:
| ![]() |
For example, in .NET there are types Brand1 and BrandBase (Brand1 inherits 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 $type property to JSON schema for types during serialization and uses it during deserialization.
Thus, serializing an instance of the Brand1 class will create a JSON object with the aforementioned $type property.
Brand1 is an object created using the BrandBase type. Since the serializer expects to get only an object of type BrandBase, and Brand1 recognizes it as a separate type that inherits from the common type BrandBase, it assigns it the $type property, which specifies the model that the object was created with, to create an object of the source type during deserialization.
In the response to the query for a list of brands, the information about Brand1 will look like this
{
"$type": "Loymax.Api.Models.BrandInfo.Brand1, Loymax.Api",
"name": "Brand1",
"description": "New Brand",
"code": "7878b563333841d79a5e5d14fde29cbe"
}