Loymax, 2025

Wiki source code of Методы API


Hide last authors
Вера Ретьева 48.1 1 (% class="root-extension__layer-composer" %)
2 (((
3
4 )))
5
Арман Бояхчян 2.1 6 (% class="lead" %)
Вера Ретьева 48.1 7 Questions related to the work of API methods:
Арман Бояхчян 6.2 8
Вера Ретьева 48.1 9 * {{showhide showmessage="Why do some API methods return the $type property?" hidemessage="Why do some API methods return the $type property?"}}|(% style="border-color:white" %)(((
Арман Бояхчян 28.2 10 (% class="box infomessage" %)
11 (((
Вера Ретьева 48.1 12 **Note:** It is reccomended to read about{{html}}<a href="https://docs.loymax.net/xwiki/bin/view/Main/General_information/Used_technologies/">the technology stack</a>{{/html}} used by the Loymax system.
Арман Бояхчян 28.2 13 )))
Арман Бояхчян 6.2 14
Арман Бояхчян 28.2 15 (((
Вера Ретьева 48.1 16 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.
Арман Бояхчян 7.1 17
Арман Бояхчян 28.2 18 (% class="box" %)
19 (((
Вера Ретьева 48.1 20 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.
21 The reverse translation of bytes into a data structure is called **deserialization**.
Арман Бояхчян 28.2 22 )))
23
Вера Ретьева 48.1 24 The Loymax system uses the **Newtonsoft.Json.JsonSerializer** for serialization/deserialization.
Арман Бояхчян 29.1 25 )))
Арман Бояхчян 43.1 26 )))|(% style="border-color:white" %){{lightbox image="Group 1 (1).png"/}}
Арман Бояхчян 28.2 27
Вера Ретьева 48.1 28 Let's take the serialization/deserialization process as an example of how the method works for {{html}}<a href="https://docs.loymax.net/xwiki/bin/view/Main/Integration/Ways_to_use_API/API_methods/Methods_of_public_api/Brands/#H41F43E43B44344743543D43843544143F43844143A43043144043543D43443E432">receiving a list of brands</a>{{/html}}
Арман Бояхчян 28.2 29
Арман Бояхчян 43.1 30 (((
31
32 )))
33
34 |(% style="border-color:white" %)(((
Вера Ретьева 48.1 35 All brands in the System are created using the same template (model), that is, they are inherited from the same data type.
Арман Бояхчян 28.2 36
Вера Ретьева 48.1 37 The algorithm for obtaining information about brands through API methods works as follows:
Арман Бояхчян 35.1 38
Вера Ретьева 48.1 39 1. The client sends a request for a list of brands (##GET: /v1.2/brands###).
40 1. The server processes the request, generates and sends an SQL-query to the database to get a list of brands.
41 1. The database, in response to a server request, returns to the server a list of brands that are translated from the byte stream back into a **.Net** object.
42 1. The server returns to the client a list of brands in JSON format. The **Newtonsoft.Json.JsonSerializer **converts the **.Net** object into JSON format.
Арман Бояхчян 43.1 43 )))|(% style="border-color:white" %)[[image:BrandBase.png]]
Арман Бояхчян 28.2 44
Вера Ретьева 48.1 45 For example, in **.NET** there are types **Brand1 ** and **BrandBase **(**Brand1 ** inherits from **BrandBase**).
Арман Бояхчян 7.1 46
47 (% class="box" %)
48 (((
Арман Бояхчян 43.1 49 ##public class BrandBase
50 {
51 public string Name { get; set; }
52 public string Description { get; set; }
53 }
54 public class Brand1 : BrandBase
55 {
56 public string Code { get; set; }
Арман Бояхчян 28.3 57 }##
Арман Бояхчян 43.1 58 )))
Арман Бояхчян 17.1 59
Вера Ретьева 48.1 60 **Newtonsoft JsonConvert** adds **$type ** property to JSON schema for types during serialization and uses it during deserialization.
Арман Бояхчян 20.1 61
Вера Ретьева 48.1 62 Thus, serializing an instance of the **Brand1 class ** will create a JSON object with the aforementioned **$type** property.
Арман Бояхчян 43.1 63
64 (% class="box infomessage" %)
65 (((
Вера Ретьева 48.1 66 **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.
Арман Бояхчян 43.1 67 )))
68
Вера Ретьева 48.1 69 In the response to the query for a list of brands, the information about **Brand1 **will look like this
Арман Бояхчян 43.1 70
71 (% class="box" %)
72 (((
73 ##{##
74
75 ## "$type": "Loymax.Api.Models.BrandInfo.Brand1, Loymax.Api",
76 "name": "Brand1",
Вера Ретьева 48.1 77 "description": "New Brand",
Арман Бояхчян 43.1 78 "code": "7878b563333841d79a5e5d14fde29cbe"
79 }##
80 ))){{/showhide}}
Вера Ретьева 48.1 81
82 (% class="root-extension__layer-composer" %)
83 (((
84
85 )))

News
Version history
Tags
Glossary
Site