Serialization method, deserialization method and first electronic device of data object

By writing attribute index values ​​and lengths into the serialized data object, the deserialization exception caused by inconsistencies between client and server versions is resolved, achieving version compatibility and independent upgrades, and simplifying maintenance.

CN115129759BActive Publication Date: 2025-11-25ECARX (HUBEI) TECHCO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210952037.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-09
Publication Date
2025-11-25
Estimated Expiration
2042-08-09

AI Technical Summary

Technical Problem

In data interaction between client and server applications on an Android system, inconsistencies in client and server versions can lead to data deserialization errors, impacting user experience.

Method used

This method provides a serialization approach applicable to different versions by writing attribute index values, attribute value content, and attribute value length to a specified position in the serialized data object. During deserialization, it determines whether the data is contained in the target data object based on the attribute index value and length, and performs correct deserialization processing.

Benefits of technology

It achieves effective compatibility between the client and server when versions are inconsistent, reduces dependencies, and simplifies the version upgrade and maintenance process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115129759B_ABST
    Figure CN115129759B_ABST
Patent Text Reader

Abstract

The application provides a serialization method, a deserialization method and a first electronic device of a data object. The serialization method is applied to a client, and the serialization method comprises the following steps: obtaining an attribute index value of a data object to be serialized on the client, and writing the attribute index value into a first specified position of an address of the data object to be serialized; obtaining attribute value content corresponding to the attribute index value in the data object to be serialized, and writing the attribute value content into a second specified position of the address of the data object to be serialized; calculating an attribute value length of the attribute value content written into the second specified position, and writing the attribute value length into a third specified position of the address of the data object to be serialized, to obtain a serialized data object. The serialized data object can be applied to a case where a deserialization version in a server application and a serialization version in a client application are inconsistent, that is, the serialized version of the client application and the deserialization version of the server application can be effectively compatible even when the two versions are inconsistent, and the compatibility is obviously improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of Internet, and in particular, to a serialization method of a data object, a deserialization method and a first electronic device. BACKGROUND

[0002] At present, data object serialization and data object deserialization are widely applied in data interaction between a client application and a server application of an Android system, and the data interaction can be realized through a Parcel (a container for packaging data). However, when the serialization version of the client application and the deserialization version of the server application are inconsistent, the server application is prone to abnormality when deserializing the serialized data transmitted by the client application, which causes errors of the server application and affects the user experience. SUMMARY

[0003] In view of the above problems, a serialization method of a data object, a deserialization method and a first electronic device are provided to overcome the above problems or at least partially solve the above problems.

[0004] An object of the present application is to provide a serialization method of a serialized data object suitable for a class of different versions from a client.

[0005] According to an aspect of the present application, a serialization method of a data object is provided, applied to a client, and the serialization method comprises the following steps.

[0006] An attribute index value of a data object to be serialized on the client is obtained, and written into a first specified position of an address of the data object to be serialized;

[0007] An attribute value content corresponding to the attribute index value in the data object to be serialized is obtained, and written into a second specified position of the address of the data object to be serialized;

[0008] An attribute value length of the attribute value content written into the second specified position is calculated, and the attribute value length is written into a third specified position of the address of the data object to be serialized, to obtain a serialized data object.

[0009] Optionally, after the step of writing into the first specified position of the address of the data object to be serialized, the serialization method further comprises the following steps.

[0010] The second specified position is obtained from the first specified position and the third specified position.

[0011] Optionally, the first specified position occupies 4 bytes.

[0012] Optionally, the third designated position occupies 4 bytes.

[0013] According to another aspect of the present application, the present application further provides a deserialization method of a data object, applied to a server side, the deserialization method comprising:

[0014] reading a serialization data object according to any one of the above;

[0015] deserializing the serialization data object according to a preset rule to obtain a deserialization data object.

[0016] Optionally, the step of deserializing the serialization data object according to the preset rule comprises:

[0017] obtaining an attribute index value of the serialization data object;

[0018] obtaining an attribute value length of the serialization data object;

[0019] obtaining a target data object of the server side according to the attribute index value;

[0020] judging whether the attribute index value of the serialization data object and / or the attribute value content corresponding to the attribute index value is contained in the target data object;

[0021] if yes, reading the attribute value content of the serialization data object according to the attribute value length and assigning it to the attribute value content corresponding to the same target index value of the target data object.

[0022] Optionally, if the attribute index value of the serialization data object and the attribute value content corresponding to the attribute index value are both not contained in the target data object, skipping the reading of the attribute value content according to the attribute value length of the serialization data object.

[0023] According to still another aspect of the present application, the present application further provides a first electronic device, comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, and the processor implements the serialization method of the data object according to any one of the above when executing the machine executable program.

[0024] According to yet another aspect of the present application, the present application further provides a second electronic device, comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, and the processor implements the deserialization method of the data object according to any one of the above when executing the machine executable program.

[0025] According to still another aspect of the present application, the present application further provides a vehicle-mounted system, comprising:

[0026] The first electronic device according to the above description; and

[0027] The second electronic device according to the above description, in signal connection with the first electronic device.

[0028] In the serialization method of the data object of the present application, the attribute index value of the data object to be serialized on the client is obtained and written in the first specified position of the address of the data object to be serialized, the attribute value content corresponding to the attribute index value in the data object to be serialized is obtained and written in the second specified position of the address of the data object to be serialized, the attribute value length of the attribute value content written in the second specified position is calculated, and the attribute value length is written in the third specified position of the address of the data object to be serialized, to obtain a serialized data object. The serialized data object can be applied to the case where the serialization version in the client application and the deserialization version in the server application are inconsistent, that is, the serialized version of the client application and the deserialization version of the server application can be effectively compatible even when they are inconsistent, obviously improving the compatibility. Moreover, the serialization version of the client application and the deserialization version of the server application are upgraded independently, reducing the dependence between them and making the maintenance of both more simple and convenient.

[0029] The above and other objects, advantages and features of the present application will become more apparent from the following detailed description of specific embodiments thereof, taken in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS

[0030] Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The accompanying drawings are included to provide a better understanding of the preferred embodiments, and are not to be considered limitations of the present application. Throughout the drawings, like reference numerals refer to similar or identical elements. In the drawings:

[0031] Figure 1 is a flow chart of a serialization method of a data object according to one embodiment of the present application;

[0032] Figure 2 is a structural schematic diagram of a serialized data object according to another embodiment of the present application;

[0033] Figure 3 is a structural schematic diagram of a serialized data object according to the prior art of the present application;

[0034] Figure 4 is a flow chart of a deserialization method of a data object according to another embodiment of the present application;

[0035] Figure 5is a flow chart of a deserialization method of a data object according to another embodiment of the present application;

[0036] Figure 6 is a structural schematic diagram of a first electronic device according to an embodiment of the present application;

[0037] Figure 7 is a structural schematic diagram of a second electronic device according to an embodiment of the present application;

[0038] Figure 8 is a structural schematic diagram of a vehicle-mounted system according to an embodiment of the present application. DETAILED DESCRIPTION

[0039] Exemplary embodiments of the present disclosure will be described herein below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it is understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the present disclosure to those skilled in the art.

[0040] Figure 1 is a flow chart of a serialization method of a data object according to an embodiment of the present application, which is applied to a client. The system type of the client can be an Android system, and of course, can be other types of systems. Referring to Figure 1 , the serialization method of the data object can include the following steps S102 to S106.

[0041] Step S102: Obtain the attribute index value of the data object to be serialized on the client, and write the attribute index value to a first specified position of the address of the data object to be serialized.

[0042] In this step, the data object to be serialized has attribute information, which generally includes a serial number (i.e., attribute index value), attribute value length, and attribute value content. The attribute index value can be obtained according to the attribute information of the data object to be serialized. The numerical type of the attribute index value can be integer. The attribute index values of different attribute indexes are different.

[0043] Step S104: Obtain the attribute value content corresponding to the attribute index value in the data object to be serialized, and write the attribute value content to a second specified position of the address of the data object to be serialized.

[0044] Step S106: Calculate the attribute value length of the attribute value content written in the second specified position, and write the attribute value length to a third specified position of the address of the data object to be serialized, to obtain a serialized data object. In this step, the numerical type of the attribute value length can be integer.

[0045] In the embodiment, the attribute index value of the data object to be serialized on the client is acquired and written in a first specified position of the address of the data object to be serialized, the attribute value content corresponding to the attribute index value in the data object to be serialized is acquired and written in a second specified position of the address of the data object to be serialized, the attribute value length of the attribute value content written in the second specified position is calculated and written in a third specified position of the address of the data object to be serialized, and a serialized data object is obtained. The serialized data object can be applied to the case that the deserialization version in the server application and the serialization version in the client application are inconsistent, that is, the serialized version of the client application and the deserialized version of the server application can be effectively compatible even when they are inconsistent, the compatibility is obviously improved, and the serialization version of the client application and the deserialization version of the server application are upgraded independently, the dependence between them is reduced, and the maintenance of them is more simple and convenient.

[0046] In an embodiment of the application, after the step of writing the attribute index value in the first specified position of the address of the data object to be serialized, the method further comprises:

[0047] The second specified position is obtained from the first specified position by spacing the third specified position.

[0048] In the embodiment, the second specified position is obtained from the first specified position by spacing the third specified position, that is, the first specified position and the second specified position are spaced by the third specified position, that is, the first specified position and the third specified position are adjacent, and the third specified position and the second specified position are adjacent. The second specified position is obtained from the first specified position by spacing the third specified position, so that the first specified position, the third specified position and the second specified position have a positional relationship, so that the attribute value content can be more easily read according to the positional relationship among them.

[0049] In the embodiment, the effect of obtaining the second specified position from the first specified position by spacing the third specified position can be seen from Figure 2 , Figure 2 is a structural schematic diagram of a serialized data object according to another embodiment of the application, Figure 2The serialized data object 1 and the serialized data object 2 are shown in the figure, and more serialized data objects can also be included, each of which can include at least one attribute information, and the attribute information can include an attribute index value, an attribute value content and an attribute value length. For example, the serialized data object 1 includes n attribute index values, n attribute value contents and n attribute value lengths. Specifically, the attribute 1 index value is located at a first specified position and occupies 4 bytes. Similarly, the attribute 1 value length is located at a third specified position adjacent to the first specified position and also occupies 4 bytes. The attribute 1 index value and the attribute 1 value content corresponding thereto are separated by 4 bytes, that is, the third specified position. When the serialized data object includes multiple attribute information, the attribute index value of each attribute information can be written after the attribute value content of the previous attribute information, that is, the attribute index value of each attribute information can be arranged after the attribute value content of the previous attribute information in terms of address and adjacent to the position of the attribute value content. For example, the attribute 2 index value is arranged after the attribute 1 value content and adjacent to the attribute 1 value content. Figure 3 is a structural diagram of a serialized data object according to the prior art of the application, and Figure 2 , Figure 3 only includes the attribute content and lacks the attribute index value and the attribute value length.

[0050] In an embodiment of the application, the first specified position can occupy 4 bytes.

[0051] In this embodiment, the attribute index value can preferably use an integer type in Java on the client side, and the corresponding byte number can preferably be 4, and other numbers of bytes can also be considered.

[0052] In an embodiment of the application, the third specified position can occupy 4 bytes.

[0053] In this embodiment, the attribute value length can preferably use an integer type in Java on the client side, and the corresponding byte number can preferably be 4, and other numbers of bytes can also be considered.

[0054] Referring to Figure 4 Based on the same concept, the application further provides a deserialization method of a data object, applied to a server side, and the system type of the server side can also be an Android system. The deserialization method can include the following steps S402 and S404.

[0055] Step S402: reading a serialized data object according to any one of the embodiments in the above.

[0056] Step S404: deserializing the serialized data object according to a preset rule to obtain a deserialized data object.

[0057] In the embodiment, the serialized data object according to any one of the above embodiments is read, and the serialized data object is deserialized according to a preset rule to obtain a deserialized data object. Even if the serialization version of the client application and the deserialization version of the server application are inconsistent, the correct deserialized data object can be obtained, the compatibility when the serialization version of the client application and the deserialization version of the server application are inconsistent can be effectively realized, the compatibility is obviously improved, and the serialization version of the client application and the deserialization version of the server application can be independently upgraded, the dependence between the two is reduced, and the maintenance of the two is more simple and convenient.

[0058] In an embodiment of the application, the step of deserializing the serialized data object according to the preset rule can include:

[0059] obtaining an attribute index value of the serialized data object;

[0060] obtaining an attribute value length of the serialized data object;

[0061] obtaining a target data object of the server according to the attribute index value;

[0062] judging whether the attribute index value of the serialized data object and / or the attribute value content corresponding to the attribute index value is contained in the target data object;

[0063] if yes, reading the attribute value content of the serialized data object according to the attribute value length, and assigning the attribute value content to the attribute value content corresponding to the target index value same as the attribute index value in the target data object.

[0064] In the embodiment, the target data object of the server is acquired according to the attribute index value, that is, the attribute information of the target data object of the server is acquired according to the attribute index value, wherein the attribute information of the target data object can include the attribute name, the attribute type and the attribute index value of the target data object, and specifically, for example, if the attribute index value of the serialized data object is the same as the attribute index value of the target data object, the target data object can be acquired. The attribute index value of the serialized data object is acquired, the attribute value length of the serialized data object is acquired, the target data object of the server is acquired according to the attribute index value, it is judged whether the attribute index value of the serialized data object and / or the attribute value content corresponding to the attribute index value is contained in the target data object, if yes, the attribute value content of the serialized data object is read according to the attribute value length, and is assigned to the attribute value content corresponding to the target index value with the same attribute index value in the target data object, which realizes that the serialized data object provided by the client is used as the criterion, instead of using the version of the server application deserialization as the criterion in the prior art, so that the serialized data object provided by the client application can be correctly expressed in the server application, and correct parsing and use of the serialized data object are realized in the case that the serialization version in the client application and the non-serialization version in the server application are inconsistent.

[0065] In an embodiment of the application, if the attribute index value of the serialized data object and the attribute value content corresponding to the attribute index value are not contained in the target data object, the attribute value content is skipped according to the attribute value length of the serialized data object.

[0066] In the embodiment, if the attribute index value of the serialized data object and the attribute value content corresponding to the attribute index value are not contained in the target data object, the attribute value content is skipped according to the attribute value length of the serialized data object, so as to avoid assigning the incorrect attribute value content to the attribute value content corresponding to the target index value with the same attribute index value in the target data object.

[0067] Referring to Figure 5 , Figure 5 is a flowchart of a deserialization method of a data object according to another embodiment of the application, which can include the following steps S502 to S514.

[0068] Step S502: reading a serialized data object according to any one of the above embodiments.

[0069] Step S504: acquiring the attribute index value of the serialized data object.

[0070] Step S506: acquiring the attribute value length of the serialized data object.

[0071] Step S508: acquiring the target data object of the server according to the attribute index value.

[0072] Step S510: judging whether the attribute index value of the serialized data object and / or the attribute value content corresponding to the attribute index value is contained in the target data object.

[0073] If yes, step S512 is executed, and if no, step S514 is executed.

[0074] Step S512: reading the attribute value content of the serialized data object according to the attribute value length, and assigning it to the attribute value content corresponding to the target index value same as the attribute index value in the target data object.

[0075] Step S514: skipping the reading of the attribute value content according to the attribute value length of the serialized data object.

[0076] In the present embodiment, after skipping the reading of the attribute value content according to the attribute value length of the serialized data object, it is further judged whether the reading of the serialized data object is finished, i.e. whether there is still attribute information to be read. If not finished, it is further returned to step S504 until all the reading is finished.

[0077] The serialization method and the deserialization method of the present application will be explained below through a specific example, which is only used for explaining the present application and does not limit the present application in any way. In the present example, the "Student, ClassTeacher class" is defined. In order to better understand, the present example provides part of the code of the student class (Student) and the class teacher class (ClassTeacher) for explanation, and the following is the information of the Student class:

[0078]

[0079]

[0080] The following are the information of two versions of the ClassTeacher, which can be in different ends (client application, server application)

[0081] The first version of the ClassTheacher (hereinafter referred to as CTV1):

[0082]

[0083] The second version of the ClassTheacher (hereinafter referred to as CTV2):

[0084]

[0085] According to the Android native serialization object mechanism (serialization method in the prior art), when the version of the client application is CTV1 and the version of the server application is CTV2, the data sent by the client after deserialization will cause the age of the Student of the client to be parsed into the age of the ClassTeacher of the server. When the version of the client application is CTV2 and the version of the server application is CTV1, the data sent by the client after deserialization will cause the age of the ClassTeacher of the client to be parsed into the age of the Student of the server. The prior art will cause the data transmitted by the client application and the data of the server application to be completely confused. In the present application, when the server application deserializes the data provided by the client (including: attribute index value, attribute value length, attribute value content), the provided data is used as the reference, rather than the version of the class of the server application as in the Android native method. When the server application is deserialized, if the attribute read does not exist in the class of the server application, the next attribute will be parsed according to the attribute value length, so that the data provided by the client application can be correctly expressed in the server application, and finally the class version in the client application and the class version in the server application are inconsistent, and the correct parsing is achieved.

[0086] Referring to Figure 6 Based on the same concept, the present application also provides a first electronic device 600. The first electronic device 600 can include a memory 601, a processor 602, and a machine executable program stored on the memory 601 and running on the processor 602, and the processor 602 implements the serialization method of the data object according to any of the above embodiments when executing the machine executable program.

[0087] Referring to Figure 7 Based on the same concept, the present application also provides a second electronic device 700. The second electronic device 700 can include a memory 701, a processor 702, and a machine executable program stored on the memory 701 and running on the processor 702, and the processor 702 implements the deserialization method of the data object according to any of the above embodiments when executing the machine executable program.

[0088] Referring to Figure 8 Based on the same concept, the present application also provides a vehicle-mounted system 800, which can include the first electronic device 600 according to the above embodiments and the second electronic device 700 according to the above embodiments. The second electronic device 700 is in signal connection with the first electronic device 600. The vehicle-mounted system 800 can be a vehicle-mounted entertainment system, a vehicle-mounted navigation system, a vehicle-mounted instrument system, and other types of vehicle-mounted systems 800 known to those skilled in the art.

[0089] The above various embodiments can be combined, and according to any one of the above preferred embodiments or a combination of the above preferred embodiments, the embodiments of the present application can achieve the following beneficial effects:

[0090] In the serialization method of the data object of the present application, the attribute index value of the data object to be serialized on the client is obtained and written into a first specified position of the address of the data object to be serialized, the attribute value content corresponding to the attribute index value in the data object to be serialized is obtained and written into a second specified position of the address of the data object to be serialized, the attribute value length of the attribute value content written into the second specified position is calculated and written into a third specified position of the address of the data object to be serialized, and a serialized data object is obtained. The serialized data object can be applied to the case where the serialization version in the client application and the deserialization version in the server application are inconsistent, that is, the serialized version of the client application and the deserialization version of the server application can be effectively compatible even when they are inconsistent, which obviously improves the compatibility. Moreover, the serialization version of the client application and the deserialization version of the server application are upgraded independently, which reduces the dependence between them and makes the maintenance of both of them more simple and convenient.

[0091] At this point, those skilled in the art should recognize that although the present application has been shown and described in detail in this paper, many other variants or modifications conforming to the principles of the present application can be directly determined or deduced according to the disclosure of the present application without departing from the spirit and scope of the present application. Therefore, the scope of the present application should be understood and recognized as covering all these other variants or modifications.

Claims

1. A serialization and deserialization method of a data object, wherein, the serialization method is applied to a client, and the serialization method comprises: obtaining an attribute index value of a data object to be serialized on the client, and writing the attribute index value to a first specified position of an address of the data object to be serialized; obtaining attribute value content corresponding to the attribute index value in the data object to be serialized, and writing the attribute value content to a second specified position of the address of the data object to be serialized; calculating an attribute value length of the attribute value content written to the second specified position, and writing the attribute value length to a third specified position of the address of the data object to be serialized, to obtain a serialized data object; the deserialization method is applied to a server, and the deserialization method comprises: reading the serialized data object; deserializing the serialized data object according to a preset rule to obtain a deserialized data object; the step of deserializing the serialized data object according to the preset rule comprises: obtaining an attribute index value of the serialized data object; obtaining an attribute value length of the serialized data object; obtaining a target data object of the server according to the attribute index value; determining whether the attribute index value of the serialized data object and / or the attribute value content corresponding to the attribute index value is contained in the target data object; if yes, reading the attribute value content of the serialized data object according to the attribute value length, and assigning the attribute value content to an attribute value content corresponding to a target index value same as the attribute index value in the target data object.

2. The serialization and deserialization method of claim 1, wherein, After the step of writing the attribute index value to the first specified position of the address of the data object to be serialized, the method further comprises: obtaining the second specified position by spacing the third specified position from the first specified position.

3. The serialization and deserialization method according to claim 1, wherein, the first specified position occupies 4 bytes.

4. The serialization and deserialization method according to claim 1, wherein, the third specified position occupies 4 bytes.

5. The serialization and deserialization method according to claim 1, wherein, if the attribute index value of the serialized data object and the attribute value content corresponding to the attribute index value are not contained in the target data object, the reading of the attribute value content is skipped according to the attribute value length of the serialized data object.

6. A first electronic device, comprising: A computer readable storage medium, comprising a memory, a processor, and a machine executable program stored on the memory and running on the processor, and the processor implements the serialization method in the serialization and deserialization method according to any one of claims 1 to 4 when executing the machine executable program.

7. A second electronic device, comprising: A computer readable storage medium, comprising a memory, a processor, and a machine executable program stored on the memory and running on the processor, and the processor implements the deserialization method in the serialization and deserialization method according to claim 1 or 5 when executing the machine executable program.

8. An in-vehicle system characterized by comprising: comprises: the first electronic device according to claim 6; and the second electronic device according to claim 7, which is signal connected with the first electronic device. ​

Citation Information

Patent Citations

  • Object serialization method, equipment and computing device

    CN106775638A