CN107038022B - Deserialization method and deserialization device - Google Patents

Deserialization method and deserialization device Download PDF

Info

Publication number
CN107038022B
CN107038022B CN201510408889.1A CN201510408889A CN107038022B CN 107038022 B CN107038022 B CN 107038022B CN 201510408889 A CN201510408889 A CN 201510408889A CN 107038022 B CN107038022 B CN 107038022B
Authority
CN
China
Prior art keywords
attribute
value
key
key information
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201510408889.1A
Other languages
Chinese (zh)
Other versions
CN107038022A (en
Inventor
马立杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba Cloud Computing Ltd
Original Assignee
Alibaba Group Holding Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201510408889.1A priority Critical patent/CN107038022B/en
Priority to PCT/CN2016/088324 priority patent/WO2017008654A1/en
Publication of CN107038022A publication Critical patent/CN107038022A/en
Application granted granted Critical
Publication of CN107038022B publication Critical patent/CN107038022B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a deserialization method and a deserialization device, wherein the method comprises the following steps: acquiring serialized data, wherein the serialized data comprises a first attribute of an object to be reconstructed; analyzing the serialized data to generate a first key-value pair, wherein the first key-value pair comprises first key information and first value information, and the first key information and the first value information have a corresponding relation; and assigning the first attribute to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the first attribute. Therefore, the attribute of the object to be reconstructed is not required to be obtained in a reflection mode in the embodiment of the application, so that excessive hardware resources are not required to be occupied, and the deserialization efficiency is improved.

Description

Deserialization method and deserialization device
Technical Field
The present application relates to the field of computer technologies, and in particular, to a deserialization method and apparatus.
Background
Serialization and deserialization are techniques commonly used in the computer arts. Serialization is used to convert the attribute values of an object into serialized data so that the serialized data can be stored or transmitted. And the deserialization is a serialized inverse process and is used for analyzing the serialized data to obtain the attribute value of the object and assigning the attribute of the object to be reconstructed according to the attribute value.
For example, User is a class representing a User, User is an object of the User class, and User has the attributes: and the attribute value of the userID is 0001. The attribute value of the user is stored as serialized data, for example, the process of storing the data in the xml format or the json format is serialization, the attribute value of the user is analyzed from the data in the xml format or the json format, and the process of assigning the attribute of the user according to the attribute value of the user is deserialization.
At present, when deserialization is realized, firstly, attributes of an object to be reconstructed are obtained in a reflection mode, then, attribute values corresponding to the attributes are obtained by analyzing serialized data, and the attributes are assigned according to the obtained attribute values. However, at present, when the attributes of the object to be reconstructed are obtained by reflection, more hardware resources are usually occupied, so that the deserialization efficiency is low.
Disclosure of Invention
The technical problem to be solved by the present application is to provide an deserialization method and apparatus, which do not need to obtain the attribute of the object to be reconstructed in a reflection manner, thereby saving hardware resources and improving deserialization efficiency.
Therefore, the technical scheme for solving the technical problem is as follows:
the application provides an deserialization method, which comprises the following steps:
acquiring serialized data, wherein the serialized data comprises a first attribute of an object to be reconstructed;
analyzing the serialized data to generate a first key-value pair, wherein the first key-value pair comprises first key information and first value information, and the first key information and the first value information have a corresponding relation;
and assigning the first attribute to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the first attribute.
Optionally, the serialized data further includes a second attribute of the object to be reconstructed; the method further comprises the following steps:
analyzing the serialized data to generate a second key-value pair, wherein the second key-value pair comprises second key information and second value information, and the second key information and the second value information have a corresponding relation;
and assigning the second attribute to the second value information corresponding to the second key information according to a preset corresponding relationship between the second key information and the second attribute.
Optionally, the first attribute has a sub-attribute;
the method further comprises the following steps: establishing a first sub-object of the object to be reconstructed;
the assigning the first attribute to the first value information corresponding to the first key information according to the preset correspondence between the first key information and the first attribute includes:
and assigning the attribute of the first sub-object to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the sub-attribute.
Optionally, the first attribute is in a set format;
the method further comprises the following steps: establishing a second sub-object of the object to be reconstructed, wherein the second sub-object is of a set type;
assigning the first attribute to the first value information corresponding to the first key information, including:
assigning the attribute of the second sub-object to the first value information corresponding to the first key information in a circulating mode to obtain the attribute value of the second sub-object;
and assigning the first attribute as the attribute value of the second sub-object.
Optionally, the acquiring serialized data includes:
calling an API corresponding to the object to be reconstructed;
and acquiring return data for calling the API, and taking the return data as the serialized data.
The present application further provides an deserialization device comprising:
an obtaining unit configured to obtain serialized data, the serialized data including a first attribute of an object to be reconstructed;
the generating unit is used for analyzing the serialized data to generate a first key-value pair, wherein the first key-value pair comprises first key information and first value information, and the first key information and the first value information have a corresponding relation;
and the assignment unit is used for assigning the first attribute to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the first attribute.
Optionally, the serialized data further includes a second attribute of the object to be reconstructed;
the generating unit is further configured to parse the serialized data to generate a second key-value pair, where the second key-value pair includes second key information and second value information, and the second key information and the second value information have a corresponding relationship;
the assignment unit is further configured to assign the second attribute to the second value information corresponding to the second key information according to a preset correspondence between the second key information and the second attribute.
Optionally, the first attribute has a sub-attribute;
the device further comprises: a first establishing unit, configured to establish a first sub-object of the object to be reconstructed;
the assignment unit is specifically configured to:
and assigning the attribute of the first sub-object to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the sub-attribute.
Optionally, the first attribute is in a set format;
the device further comprises: a second establishing unit, configured to establish a second sub-object of the object to be reconstructed, where the second sub-object is a set type;
when the first attribute is assigned to the first value information corresponding to the first key information, the assignment unit is specifically configured to:
assigning the attribute of the second sub-object to the first value information corresponding to the first key information in a circulating mode to obtain the attribute value of the second sub-object;
and assigning the first attribute as the attribute value of the second sub-object.
Optionally, the obtaining unit is specifically configured to:
calling an API corresponding to the object to be reconstructed;
and acquiring return data for calling the API, and taking the return data as the serialized data.
According to the technical scheme, after the serialized data is obtained, the serialized data is analyzed to generate the first key value pair, wherein the serialized data comprises the first attribute of the object to be reconstructed, and the first key value pair comprises the first key information and the first value information which have the corresponding relation. Since the object to be reconstructed has the first attribute, which is an inherent feature of the object to be reconstructed, in this embodiment of the application, the attribute of the object to be reconstructed does not need to be obtained in a reflection manner, but a corresponding relationship between the first attribute and the first key information is preset, so that the first attribute can be assigned as the first value information corresponding to the first key information according to the corresponding relationship, and deserialization of the first attribute of the object to be reconstructed is achieved. Therefore, the attribute of the object to be reconstructed is not required to be obtained in a reflection mode in the embodiment of the application, so that excessive hardware resources are not required to be occupied, and the deserialization efficiency is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art according to the drawings.
Fig. 1 is a schematic flow chart of an embodiment of a method provided in an embodiment of the present application;
FIG. 2 is a schematic flow chart diagram illustrating another embodiment of a method provided by an embodiment of the present application;
fig. 3 is a schematic structural diagram of an embodiment of an apparatus according to an embodiment of the present disclosure.
Detailed Description
The present deserialization method is explained below by way of an example.
User is a class representing a User, User is an object of a User class, i.e. an instance of the User class, and User has attributes: and the user ID, wherein the attribute value of the attribute user ID is 0001, and the attribute value 0001 of the user is converted into serialized data through serialization, such as data in a json format: { "userID": 0001 "}
The process of deserialization is: firstly, obtaining the attribute of the user in a reflection mode: and then obtaining an attribute value corresponding to the attribute by analyzing the serialized data, for example, matching the attribute userID obtained by reflection with the serialized data to obtain an attribute value 0001 corresponding to the attribute userID, and assigning a value to the attribute userID according to the obtained attribute value 0001 to realize the deserialization of the attribute userID. And when all the attributes of the user are assigned, the user of the object is reconstructed.
However, when the attribute of the user is obtained by reflection, more hardware resources are usually occupied, and thus the deserialization efficiency is low.
In addition, this approach has the following problems: because some programming languages do not support obtaining the attributes of the object to be reconstructed in a reflection mode, deserialization may not be achieved; since the serialized data may exist in a plurality of formats, such as an xml format or a json format, different program codes need to be written for different formats to assign values to the attributes of the object to be reconstructed.
The embodiment of the application provides a deserialization method and device, which do not need to obtain the attribute of an object to be reconstructed in a reflection mode, so that hardware resources are saved and deserialization efficiency is improved.
In order to make those skilled in the art better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Referring to fig. 1, an embodiment of the present application provides a method embodiment of a deserialization method, which includes:
101: serialized data is obtained, the serialized data including a first attribute of an object to be reconstructed.
In this embodiment, the serialized data may be data in xml format or json format. For example, the serialized data may be data in json format:
{“userID”:“0001”}
wherein the userID is the first attribute.
The serialized data also includes a first attribute value, and the first attribute has a corresponding relationship with the first attribute value.
102: the serialized data is parsed to generate a first key-value pair.
In this embodiment of the present application, the serialized data may be parsed to generate the first Key-Value pair, where the first Key-Value pair includes first Key information (Key) and first Value information (Value), and the first Key information and the first Value information have a corresponding relationship. Wherein the first key information is used for representing the first attribute, and the first value information is used for representing the value of the first attribute.
For example, if the serialized data is data in json format:
{“userID”:“0001”}
the first key-value pair generated may be:
{User.userID=0001}
user id is the first key information, and 0001 is the first value information.
103: and assigning the first attribute to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the first attribute.
In this embodiment of the present application, since the object to be reconstructed has the first attribute, which is an inherent feature of the object to be reconstructed, the application does not need to obtain the attribute of the object to be reconstructed in a reflection manner, but can preset a correspondence relationship between the first attribute of the object to be reconstructed and the first key information, and assign the first attribute as the first value information corresponding to the first key information according to the correspondence relationship. The first key information may be regarded as a path of the attribute value of the first attribute, and the application actually finds the attribute value of the first attribute, that is, the first value information, using the path, thereby assigning the first attribute using the first value information.
For example, if the first key information is: the user id is 0001, and the correspondence between the first attribute user id and the first key information user is preset, so that the user id may be assigned to 0001 corresponding to the user.
According to the technical scheme, after the serialized data is obtained, the serialized data is analyzed to generate the first key value pair, wherein the serialized data comprises the first attribute of the object to be reconstructed, and the first key value pair comprises the first key information and the first value information which have the corresponding relation. Since the object to be reconstructed has the first attribute, which is an inherent feature of the object to be reconstructed, in this embodiment of the application, the attribute of the object to be reconstructed does not need to be obtained in a reflection manner, but a corresponding relationship between the first attribute and the first key information is preset, so that the first attribute can be assigned as the first value information corresponding to the first key information according to the corresponding relationship, and deserialization of the first attribute of the object to be reconstructed is achieved. Therefore, the attribute of the object to be reconstructed is not required to be obtained in a reflection mode in the embodiment of the application, so that excessive hardware resources are not required to be occupied, and the deserialization efficiency is improved.
In addition, because the application does not need to obtain the attributes of the object to be reconstructed in a reflection mode, the problem of unsupported programming language no longer exists, and the method embodiment of the application is suitable for various different programming languages, such as Java, C # and the like. And the first key value pair is generated according to the deserialized data, and then the first attribute is assigned according to the first key value pair, so that even if the serialized data has different formats, such as an xml format and a json format, the assignment of the first attribute can be realized only by the same program.
In the embodiment of the present Application, the deserialization data may also be obtained by calling an Application Programming Interface (API). Specifically, 101 in the present embodiment includes: calling an API corresponding to the object to be reconstructed; and acquiring return data for calling the API, and taking the return data as the serialized data.
In the above embodiment, only the deserialization process of the first attribute is described, and if the object to be reconstructed further includes other attributes besides the first attribute, the deserialization of the other attributes may be performed in a similar manner. For example, the object to be reconstructed may have at least two attributes, then 102 may analyze the serialized data to generate a key value pair list, where the key value pair list includes at least two key value pairs, and key information and value information in each key value pair have a corresponding relationship, and 103 searches for corresponding value information through the key information in the key value pair list, and assigns the value information to the corresponding attribute of the object to be reconstructed. The following embodiments are described taking as an example that the object to be reconstructed includes two attributes.
Referring to fig. 2, another method embodiment of the deserialization method is provided in the embodiment of the present application, which includes:
201: serialized data is obtained, the serialized data including a first attribute and a second attribute of an object to be reconstructed.
For example, the serialized data may be data in json format:
{“userID”:“0001”,
“userAddress”:“address01”}
the first attribute is an attribute 'userID', and the second attribute is 'userAddress'.
The serialized data also includes a first attribute value and a second attribute value, the first attribute having a correspondence with the first attribute value, the second attribute having a correspondence with the second attribute value.
202: parsing the serialized data to generate a key-value pair list, the key-value pair list comprising a first key-value pair and a second key-value pair.
The first key-value pair comprises first key information and first value information, and the first key information and the first value information have a corresponding relation. The second key-value pair includes second key information and second value information, and the second key information and the second value information have a corresponding relationship. Wherein the first key information is used for representing the first attribute, and the first value information is used for representing the value of the first attribute. The second key information is used for representing the second attribute, and the second value information is used for representing the value of the second attribute.
For example, if the serialized data is data in json format:
{“userID”:“0001”,“userAddress”:“address01”}
the generated list of key-value pairs may be:
{User.userID=0001,User.userAddress=address01}
user id is the first key information, 0001 is the first value information, user address is the second key information, and address01 is the second value information.
In the java language, the list of key-value pairs may be stored in a map object.
203: and assigning the first attribute to the first value information corresponding to the first key information according to a preset corresponding relationship between the first key information and the first attribute, and assigning the second attribute to the second value information corresponding to the second key information according to a preset corresponding relationship between the second key information and the second attribute.
For example, if the first key information is user.userid, the second key information is user.useraddress, and the first attribute "userID" and the first key information "user.userid" are preset to have a corresponding relationship, and the second attribute "userAddress" and the second key information "user.useraddress" are preset to have a corresponding relationship, so that the "userAddress" may be assigned to 0001, that is, the "userAddress" may be assigned to 0001, and the "userAddress" may be assigned to address01, that is, the "userAddress may be assigned to address 01.
It should be further noted that, in the present application, the first key value pair is generated according to the deserialization data, and then the first attribute is assigned according to the first key value pair, instead of being directly assigned according to the deserialization data, which also has a technical effect of reducing the number of times of parsing the deserialization data. For example, if the serialized data is data in json format:
{“userID”:“0001”,
“userAddress”:“address01”}
the object to be reconstructed has two properties: and if the two attributes are directly assigned without generating the first key value pair, analyzing the deserialized data at least twice, wherein the first analysis is as follows: matching the attribute userID with the deserialized data to obtain an attribute value 0001 corresponding to the attribute userID, and analyzing for the second time as: and matching the attribute useradaddress with the deserialized data to obtain an attribute value of address01 corresponding to the attribute useradaddress. And if the deserialization method provided by the application is adopted, no matter how many attributes the object to be rebuilt has, the deserialization data only needs to be analyzed once to generate a key value pair list, and then the attributes of the object to be rebuilt are assigned according to each key value in the key value pair list. Therefore, the data to be serialized do not need to be analyzed for multiple times, and the workload is reduced.
In this embodiment of the present application, the first attribute may be a simple type or a complex type, which are described below.
Simple type means that the first attribute has no sub-attribute, i.e. the first attribute is a direct attribute of the object to be reconstructed. For example, the deserialization data is data in json format:
{“userID”:“0001”}
the userID is a direct attribute of the object user, so that the userID belongs to a simple type.
For a simple type, 103 may assign the first attribute as the first value information directly.
For example, the first key-value pair generated may be:
{User.userID=0001}
user id is the first key information, and 0001 is the first value information.
The first attribute may be assigned by the following Java code:
user.setuserID(map.get("User.userID"));
the code table shows a correspondence relationship between a preset first key information user. The map object stores the first key-value pair.
And in the code, the user ID and the user are both of character string types, so that type conversion is not needed. If the user id is a character string type and the user id is another type, for example, an int type, data conversion is required, and the first attribute may be specifically assigned by the following Java code:
user.setUserID(Integer.valueOf(map.get("User.userID")));
the complex type means that the first attribute has a sub-attribute. For example, the deserialization data is data in json format:
{"vpcAttributes":{"NatIpAddress":"Address02"},
and the NatIPaddress is a sub-attribute of the first attribute vpcAttributes.
In this embodiment of the present application, if the first attribute is a complex type, this embodiment of the present application may further include: establishing a first sub-object of the object to be reconstructed; wherein the first sub-object is actually the first attribute. 103, assigning the first attribute to the first value information corresponding to the first key information according to the preset correspondence between the first key information and the first attribute, including: and assigning the attribute of the first sub-object to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the sub-attribute. The following examples are given.
Still taking the data in json format as an example, the first key-value pair generated may be:
{User.VpcAttributes.NatIpAddress=Address02}
wherein, user.vpcatributes.natipaddress is the first key information, and Address02 is the first value information. Wherein the first key information corresponds to the first attribute and a sub-attribute of the first attribute.
The child object vpctatributes may be built by the following Java code:
VpcAttributes vpcAttributes=new VpcAttributes();
the attributes of the sub-object vpctatributes can be assigned by the following Java code:
vpattatributes. setnatipaddress (map. get ("user. vpattatributes. natipaddress")); the code table shows a correspondence relationship in which the first key information user vpcatributes NatIpAddress and the child attribute NatIpAddress are set in advance.
In this embodiment of the present application, the first attribute may also be in a collection format, and at this time, the first attribute may be assigned in a round-robin manner. Specifically, the method further comprises: establishing a second sub-object of the object to be reconstructed, wherein the second sub-object is of a set type; 103, assigning the first attribute to the first value information corresponding to the first key information includes: assigning the attribute of the second sub-object to the first value information corresponding to the first key information in a circulating manner to obtain the attribute value of the second sub-object; and assigning the first attribute as the attribute value of the second sub-object. The Set format may be a list format, a Set format, or an array format. The collection type may be a list type, a Set type, or an array type, etc.
The above-described cyclic assignment is exemplified below.
The deserialization data may be data in a josn format:
{"InnerIpAddress":
["10.165.103.41","10.165.103.42"]}
wherein InnerIpAddress is the first attribute, and the first attribute is in a set format.
The first key-value pair generated may be:
{User.InnerIpAddress[0]=10.165.103.41}
wherein user. lnneripaddress [0] is the first key information, and 10.165.103.41 is the first value information. Wherein the first key information can indicate that the first attribute is in an aggregate format and can indicate that the first value information is located at a position of the first attribute in the aggregate format. Lnneripaddress [0] for example, indicates that the first value information is the 0 th bit of the first attribute.
The second child object lnneripaddress may be established by the following Java code:
List<String>innerIpAddress=new ArrayList<String>();
the second child object lnneripaddress may be assigned by the following Java code:
Figure BDA0000758405400000111
the first attribute may be assigned by the following Java code:
user.setInnerIpAddress(innerIpAddress);
and the user is the object to be reconstructed.
Corresponding to the above method embodiment, the present application further provides an embodiment of an deserializing device, which is specifically described below.
Referring to fig. 3, an embodiment of the present application provides an apparatus embodiment of an deserializing apparatus, which includes: an acquisition unit 301, a generation unit 302 and an assignment unit 303.
The acquisition unit 301 is configured to acquire serialized data, which includes a first property of an object to be reconstructed.
In the embodiment of the application, the serialized data may be data in an xml format or a json format.
The serialized data also includes a first attribute value, and the first attribute has a corresponding relationship with the first attribute value.
The generating unit 302 is configured to parse the serialized data to generate a first key-value pair.
In this embodiment of the application, the generating unit 302 may analyze the serialized data to generate the first key-value pair, where the first key-value pair includes first key information and first value information, and the first key information and the first value information have a corresponding relationship. Wherein the first key information is used for representing the first attribute, and the first value information is used for representing the value of the first attribute.
The assigning unit 303 is configured to assign the first attribute to the first value information corresponding to the first key information according to a preset correspondence between the first key information and the first attribute.
In this embodiment of the present application, since the object to be reconstructed has the first attribute, which is an inherent feature of the object to be reconstructed, the application does not need to obtain the attribute of the object to be reconstructed in a reflection manner, but can preset a correspondence relationship between the first attribute of the object to be reconstructed and the first key information, and assign the first attribute as the first value information corresponding to the first key information according to the correspondence relationship. The first key information may be regarded as a path of the attribute value of the first attribute, and the application actually finds the attribute value of the first attribute, that is, the first value information, using the path, thereby assigning the first attribute using the first value information.
As can be seen from the foregoing technical solutions, after the obtaining unit 301 obtains the serialized data, the generating unit 302 analyzes the serialized data to generate a first key value pair, where the serialized data includes a first attribute of an object to be reconstructed, and the first key value pair includes first key information and first value information that have a corresponding relationship. Since the object to be reconstructed has the first attribute, which is an inherent feature of the object to be reconstructed, in this embodiment of the application, it is not necessary to obtain the attribute of the object to be reconstructed in a reflection manner, but a correspondence between the first attribute and the first key information is preset, so that the assigning unit 303 may assign the first attribute to the first value information corresponding to the first key information according to the correspondence, thereby implementing deserialization of the first attribute of the object to be reconstructed. Therefore, the attribute of the object to be reconstructed is not required to be obtained in a reflection mode in the embodiment of the application, so that excessive hardware resources are not required to be occupied, and the deserialization efficiency is improved.
In addition, because the application does not need to obtain the attributes of the object to be reconstructed in a reflection mode, the problem of unsupported programming language is avoided, so that the device embodiment of the application is suitable for various different programming languages, such as Java, C # and the like. And the first key value pair is generated according to the deserialized data, and then the first attribute is assigned according to the first key value pair, so that even if the serialized data has different formats, such as an xml format and a json format, the assignment of the first attribute can be realized only by the same program.
In the embodiment of the present application, the deserialization data may also be obtained by calling an API. Specifically, the obtaining unit 301 in this embodiment is specifically configured to: calling an API corresponding to the object to be reconstructed; and acquiring return data for calling the API, and taking the return data as the serialized data.
In the above embodiment, only the deserialization process of the first attribute is described, and if the object to be reconstructed further includes other attributes besides the first attribute, the deserialization of the other attributes may be performed in a similar manner. For example, the object to be reconstructed may have at least two attributes, the generating unit 302 may analyze the serialized data to generate a key value pair list, where the key value pair list includes at least two key value pairs, and key information and value information in each key value pair have a corresponding relationship, and the assigning unit 303 searches for corresponding value information through the key information in the key value pair list and assigns the corresponding attribute to the object to be reconstructed.
For example, the serialized data also includes a second property of the object to be reconstructed. The serialized data further comprises a second attribute value, and the second attribute value have a corresponding relation.
The generating unit 302 is further configured to parse the serialized data to generate a second key-value pair, where the second key-value pair includes second key information and second value information, and the second key information and the second value information have a corresponding relationship. The second key information is used for representing the second attribute, and the second value information is used for representing the value of the second attribute. The first key-value pair and the second key-value pair may form a list of key-value pairs. In the java language, the list of key-value pairs may be stored in a map object.
The assigning unit 303 is further configured to assign the second attribute to the second value information corresponding to the second key information according to a preset correspondence between the second key information and the second attribute.
It should be further noted that, in the present application, the first key value pair is generated according to the deserialization data, and then the first attribute is assigned according to the first key value pair, instead of being directly assigned according to the deserialization data, which also has a technical effect of reducing the number of times of parsing the deserialization data.
In this embodiment of the present application, the first attribute may be a simple type or a complex type, which are described below.
Simple type means that the first attribute has no sub-attribute, i.e. the first attribute is a direct attribute of the object to be reconstructed. For a simple type, the assigning unit 303 may assign the first attribute as the first value information directly.
The complex type means that the first attribute has a sub-attribute. In this embodiment of the present application, if the first attribute is a complex type, the apparatus of this embodiment of the present application may further include: a first establishing unit, configured to establish a first sub-object of the object to be reconstructed; the assignment unit 301 is specifically configured to: and assigning the attribute of the first sub-object to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the sub-attribute.
In this embodiment of the present application, the first attribute may also be in a collection format, and at this time, the first attribute may be assigned in a round-robin manner. Specifically, the first attribute is in a set format; the device of the embodiment of the application further comprises: a second establishing unit, configured to establish a second sub-object of the object to be reconstructed, where the second sub-object is a set type; when assigning the first attribute to the first value information corresponding to the first key information, the assigning unit 303 is specifically configured to: assigning the attribute of the second sub-object to the first value information corresponding to the first key information in a circulating mode to obtain the attribute value of the second sub-object; and assigning the first attribute as the attribute value of the second sub-object. The Set format may be a list format, a Set format, or an array format. The collection type may be a list type, a Set type, or an array type, etc.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

Claims (8)

1. A method of deserialization, comprising:
acquiring serialized data, wherein the serialized data comprises a first attribute of an object to be reconstructed and a second attribute of the object to be reconstructed;
analyzing the serialized data to generate a first key-value pair and a second key-value pair, wherein the first key-value pair comprises first key information and first value information, the first key information and the first value information have a corresponding relation, the second key-value pair comprises second key information and second value information, and the second key information and the second value information have a corresponding relation;
assigning the first attribute to the first value information corresponding to the first key information according to a preset corresponding relationship between the first key information and the first attribute;
and assigning the second attribute to the second value information corresponding to the second key information according to a preset corresponding relationship between the second key information and the second attribute.
2. The method of claim 1, wherein the first attribute has a sub-attribute;
the method further comprises the following steps: establishing a first sub-object of the object to be reconstructed;
the assigning the first attribute to the first value information corresponding to the first key information according to the preset correspondence between the first key information and the first attribute includes:
and assigning the attribute of the first sub-object to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the sub-attribute.
3. The method of claim 1, wherein the first attribute is a collection format;
the method further comprises the following steps: establishing a second sub-object of the object to be reconstructed, wherein the second sub-object is of a set type;
assigning the first attribute to the first value information corresponding to the first key information, including:
assigning the attribute of the second sub-object to the first value information corresponding to the first key information in a circulating mode to obtain the attribute value of the second sub-object;
and assigning the first attribute as the attribute value of the second sub-object.
4. The method of any of claims 1 to 3, wherein the obtaining serialized data comprises:
calling an API corresponding to the object to be reconstructed;
and acquiring return data for calling the API, and taking the return data as the serialized data.
5. An deserializing apparatus, comprising:
an obtaining unit, configured to obtain serialized data, where the serialized data includes a first attribute of an object to be reconstructed and a second attribute of the object to be reconstructed;
a generation unit, configured to parse the serialized data to generate a first key-value pair, where the first key-value pair includes first key information and first value information, and further configured to parse the serialized data to generate a second key-value pair, where the second key-value pair includes second key information and second value information, and the second key information and the second value information have a corresponding relationship;
an assignment unit, configured to assign the first attribute to the first value information corresponding to the first key information according to a preset correspondence between the first key information and the first attribute; and the attribute evaluation module is further configured to assign the second attribute to the second value information corresponding to the second key information according to a preset correspondence between the second key information and the second attribute.
6. The apparatus of claim 5, wherein the first attribute has a sub-attribute;
the device further comprises: a first establishing unit, configured to establish a first sub-object of the object to be reconstructed;
the assignment unit is specifically configured to:
and assigning the attribute of the first sub-object to the first value information corresponding to the first key information according to the preset corresponding relation between the first key information and the sub-attribute.
7. The apparatus of claim 5, wherein the first attribute is in a collection format;
the device further comprises: a second establishing unit, configured to establish a second sub-object of the object to be reconstructed, where the second sub-object is a set type;
when the first attribute is assigned to the first value information corresponding to the first key information, the assignment unit is specifically configured to:
assigning the attribute of the second sub-object to the first value information corresponding to the first key information in a circulating mode to obtain the attribute value of the second sub-object;
and assigning the first attribute as the attribute value of the second sub-object.
8. The apparatus according to any one of claims 5 to 7, wherein the obtaining unit is specifically configured to:
calling an API corresponding to the object to be reconstructed;
and acquiring return data for calling the API, and taking the return data as the serialized data.
CN201510408889.1A 2015-07-13 2015-07-13 Deserialization method and deserialization device Active CN107038022B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201510408889.1A CN107038022B (en) 2015-07-13 2015-07-13 Deserialization method and deserialization device
PCT/CN2016/088324 WO2017008654A1 (en) 2015-07-13 2016-07-04 Deserialization method and apparatus

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510408889.1A CN107038022B (en) 2015-07-13 2015-07-13 Deserialization method and deserialization device

Publications (2)

Publication Number Publication Date
CN107038022A CN107038022A (en) 2017-08-11
CN107038022B true CN107038022B (en) 2021-01-29

Family

ID=57756802

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510408889.1A Active CN107038022B (en) 2015-07-13 2015-07-13 Deserialization method and deserialization device

Country Status (2)

Country Link
CN (1) CN107038022B (en)
WO (1) WO2017008654A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
DE102018208702A1 (en) 2018-06-01 2019-12-05 Volkswagen Aktiengesellschaft Covering part, method and apparatus for producing a trim part
CN109871519A (en) * 2019-02-18 2019-06-11 北京思特奇信息技术股份有限公司 A kind of the JSON unserializing method, apparatus and storage medium of no hierarchical structure
CN112286594B (en) * 2020-10-10 2024-07-12 百度(中国)有限公司 Object serialization and deserialization method and device, electronic device and medium

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7467374B2 (en) * 2003-11-05 2008-12-16 Microsoft Corporation Serialization for structured tracing in managed code
US8805776B2 (en) * 2008-06-26 2014-08-12 Microsoft Corporation Relationship serialization and reconstruction for entities
CN101661391B (en) * 2009-09-24 2013-08-28 金蝶软件(中国)有限公司 Object serializing method, object deserializing method, device and system
CN102750268A (en) * 2012-06-19 2012-10-24 山东中创软件商用中间件股份有限公司 Object serializing method as well as object de-serializing method, device and system
CN103605518B (en) * 2013-11-19 2017-12-19 北京国双科技有限公司 Object unserializing method and apparatus
JP6044960B2 (en) * 2013-12-26 2016-12-14 インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation Method, apparatus and computer program for specializing serializer
CN104360862A (en) * 2014-11-20 2015-02-18 浪潮通用软件有限公司 Xml serialization model implementation method based on attribute label and configuration file under Net platform
CN104360865B (en) * 2014-11-28 2018-05-18 中国建设银行股份有限公司 A kind of sequencing method, unserializing method and relevant device

Also Published As

Publication number Publication date
WO2017008654A1 (en) 2017-01-19
CN107038022A (en) 2017-08-11

Similar Documents

Publication Publication Date Title
CN106919509B (en) Client generation method and device and electronic equipment
JP5298117B2 (en) Data merging in distributed computing
US9965300B2 (en) Message matching for opaque service virtualization
CN111026931B (en) Data query method, device, equipment and medium
CN107038022B (en) Deserialization method and deserialization device
CN109062560B (en) Method and apparatus for generating information
CN113448985A (en) API (application program interface) interface generation method, calling method and device and electronic equipment
CN110688096A (en) Method, device, medium and electronic equipment for constructing application program containing plug-in
CN113778897A (en) Automatic test method, device, equipment and storage medium of interface
CN106126299B (en) Service plug-in processing method and device
CN113792138B (en) Report generation method and device, electronic equipment and storage medium
CN110569230A (en) Method, system and equipment for interconversion between database design model and design document
CN113742231A (en) Protobuf protocol dynamic analysis-based number making method and device
CN112883088B (en) Data processing method, device, equipment and storage medium
CN110569243B (en) Data query method, data query plug-in and data query server
CN112835901A (en) File storage method and device, computer equipment and computer readable storage medium
CN110580212B (en) Data export method and device of application program, electronic equipment and storage medium
CN109408577B (en) ORACLE database JSON analysis method, system, device and storable medium
CN111124378B (en) Code generation method and device
CN110881030A (en) Logstack-based method and device for recording operation logs of web service administrator
CN111124883A (en) Test case library introduction method, system and equipment based on tree form
CN111767498A (en) Method and device for realizing file information sharing
CN109992293B (en) Method and device for assembling Android system component version information
CN108984221B (en) Method and device for acquiring multi-platform user behavior logs
CN115099196A (en) Method and device for converting message into data entity

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20230612

Address after: Room 1-2-A06, Yungu Park, No. 1008 Dengcai Street, Sandun Town, Xihu District, Hangzhou City, Zhejiang Province

Patentee after: Aliyun Computing Co.,Ltd.

Address before: Box four, 847, capital building, Grand Cayman Island capital, Cayman Islands, UK

Patentee before: ALIBABA GROUP HOLDING Ltd.