WO2017008654A1 - 一种反序列化方法及装置 - Google Patents

一种反序列化方法及装置 Download PDF

Info

Publication number
WO2017008654A1
WO2017008654A1 PCT/CN2016/088324 CN2016088324W WO2017008654A1 WO 2017008654 A1 WO2017008654 A1 WO 2017008654A1 CN 2016088324 W CN2016088324 W CN 2016088324W WO 2017008654 A1 WO2017008654 A1 WO 2017008654A1
Authority
WO
WIPO (PCT)
Prior art keywords
attribute
value
key
key information
information
Prior art date
Application number
PCT/CN2016/088324
Other languages
English (en)
French (fr)
Inventor
马立杰
Original Assignee
阿里巴巴集团控股有限公司
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 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2017008654A1 publication Critical patent/WO2017008654A1/zh

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

Definitions

  • the present application relates to the field of computer technology, and in particular, to a deserialization method and apparatus.
  • Serialization and deserialization are common techniques in the computer field. Serialization is used to convert an attribute value of an object into serialized data so that serialized data can be saved or transferred. De-serialization is the inverse of serialization. It is used to parse the serialized data to obtain the attribute value of the object, and assign the attribute of the object to be reconstructed according to the attribute value.
  • User is a class that represents a user
  • user is an object of User class
  • user has the attribute: userID
  • the attribute value of attribute userID is 0001.
  • the process of saving the user attribute value as serialized data, such as xml format or json format data, is a serialization, and the user attribute value is parsed from the xml format or the json format data, according to the user attribute value.
  • the process of assigning a value to a user is a deserialization.
  • the attribute of the object to be reconstructed is first obtained by means of reflection, and then the attribute value corresponding to the attribute is obtained by parsing the serialized data, and the attribute is assigned according to the obtained attribute value.
  • the hardware resources are usually occupied, which results in low efficiency of deserialization.
  • the technical problem to be solved by the present application is to provide a deserialization method and apparatus, which do not need to obtain the attributes of the object to be reconstructed by means of reflection, thereby saving hardware resources and improving the efficiency of deserialization.
  • the application provides a deserialization method, including:
  • serialized data including a first attribute of the object to be reconstructed
  • the serialized data further includes a second attribute of the object to be reconstructed; the method further includes:
  • Parsing the serialized data to generate a second key value pair the second key value pair includes second key information and second value information, and the second key information has a correspondence relationship with the second value information ;
  • the second attribute is assigned to the second value information corresponding to the second key information according to a preset relationship between the second key information and the second attribute.
  • the first attribute has a sub-attribute
  • the method further includes: establishing a first sub-object of the object to be reconstructed;
  • the attribute of the first sub-object is assigned to the first value information corresponding to the first key information according to a preset relationship between the first key information and the sub-attribute.
  • the first attribute is a set format.
  • the method further includes: establishing a second sub-object of the object to be reconstructed, where the second sub-object is a collection type;
  • the first attribute is assigned to the attribute value of the second sub-object.
  • the obtaining the serialized data includes:
  • the return data of the calling API is obtained, and the returned data is taken as the serialized data.
  • the application also provides a deserialization device, comprising:
  • An obtaining unit configured to acquire serialized data, where the serialized data includes a first attribute of an object to be reconstructed
  • a generating unit configured to parse the serialized data to generate a first key value pair, the first key value pair including first key information and first value information, the first key information and the first Value information has 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.
  • 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, the second key value pair includes second key information and second value information, and the second key information
  • the second value information has 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 .
  • the first attribute has a sub-attribute
  • the device further includes: a first establishing unit, where the first establishing unit is configured to establish a first sub-object of the object to be reconstructed;
  • the evaluation unit is specifically configured to:
  • the attribute of the first sub-object is assigned to the first value information corresponding to the first key information according to a preset relationship between the first key information and the sub-attribute.
  • the first attribute is a set format.
  • the device further includes: a second establishing unit, the second establishing unit is configured to establish a second sub-object of the object to be reconstructed, and the second sub-object is a set type;
  • the evaluation unit is specifically configured to:
  • the first attribute is assigned to the attribute value of the second sub-object.
  • the obtaining unit is specifically configured to:
  • the return data of the calling API is obtained, and the returned data is taken as the serialized data.
  • the embodiment of the present application parses the serialized data to generate a first key value pair, where the serialized data includes a first attribute of the object to be reconstructed,
  • the first key value pair includes first key information and first value information having a corresponding relationship.
  • the object to be reconstructed has the intrinsic feature of the object to be reconstructed, and therefore, in the embodiment of the present application, the attribute of the object to be reconstructed is not required to be obtained by reflection, but the foregoing is set in advance.
  • the first attribute and the first key information have a corresponding relationship, so that the first attribute is assigned to the first value information corresponding to the first key information according to the corresponding relationship, and the Deserializing the first attribute of the reconstructed object. It can be seen that, since the attributes of the object to be reconstructed are not required to be obtained by reflection in the embodiment of the present application, it is not necessary to occupy excessive hardware resources, thereby improving the efficiency of deserialization.
  • FIG. 1 is a schematic flowchart diagram of an embodiment of a method according to an embodiment of the present disclosure
  • FIG. 2 is a schematic flowchart diagram of another method embodiment according to an embodiment of the present disclosure.
  • FIG. 3 is a schematic structural diagram of an apparatus according to an embodiment of the present application.
  • User is a class representing the user
  • user is an object of the User class, that is, an instance of the User class
  • user has the attribute: userID
  • the attribute value of the attribute userID is 0001
  • the attribute value of the user is converted to serialized by serialization.
  • Data such as data in json format: ⁇ "userID": "0001" ⁇
  • the process of deserialization is to first obtain the attribute that user has by reflection: userID, and then obtain the attribute value corresponding to the attribute by parsing the serialized data, for example, matching the attribute userID obtained by reflection with the serialized data, thereby
  • the attribute value corresponding to the attribute userID is obtained as 0001, and the attribute userID is assigned according to the obtained attribute value 0001, that is, the deserialization of the attribute userID is implemented.
  • the object user is reconstructed.
  • this method has the following problems: Since some programming languages do not support the properties of the object to be reconstructed by reflection, it may result in the inability to implement deserialization; since serialized data may exist in multiple formats, such as xml format. Or json format, so for different formats you need to write different program code to assign the attributes of the reconstructed object.
  • the embodiment of the present application provides a deserialization method and device, which does not need to obtain the attributes of the object to be reconstructed by means of reflection, thereby saving hardware resources to improve the efficiency of deserialization.
  • an embodiment of the present application provides an embodiment of a method for deserialization.
  • the embodiment includes:
  • the serialized data may be data in an xml format or a json format.
  • the serialized data can be data in json format:
  • the userID is the first attribute.
  • the serialized data further includes a first attribute value, and the first attribute has a corresponding relationship with the first attribute value.
  • 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), The first key information and the first value information have a corresponding relationship.
  • the first key information is used to represent the first attribute
  • the first value information is used to represent the first attribute value.
  • serialized data is data in json format:
  • the generated first key value pair can be:
  • the User.userID is the first key information, and 0001 is the first value information.
  • the first attribute is assigned to the first value information corresponding to the first key information according to a preset relationship between the first key information and the first attribute.
  • the present application since the object to be reconstructed has the first attribute being an intrinsic feature of the object to be reconstructed, the present application does not need to obtain the attribute of the object to be reconstructed by means of reflection, but may Presetting that the first attribute of the object to be reconstructed has a corresponding relationship with the first key information, and assigning the first attribute to the corresponding one of the first key information according to the corresponding relationship
  • the first value information may be regarded as a path of the attribute value of the first attribute, and the application actually uses the path to find the attribute value of the first attribute, that is, the first value information.
  • the first attribute is then assigned with the first value information.
  • the embodiment of the present application advances the serialized data.
  • the row parsing generates a first key value pair, wherein the serialized data includes a first attribute of the object to be reconstructed, and the first key value pair includes first key information and first value information having a corresponding relationship.
  • the object to be reconstructed has the intrinsic feature of the object to be reconstructed, and therefore, in the embodiment of the present application, the attribute of the object to be reconstructed is not required to be obtained by reflection, but the foregoing is set in advance.
  • the first attribute and the first key information have a corresponding relationship, so that the first attribute is assigned to the first value information corresponding to the first key information according to the corresponding relationship, and the Deserializing the first attribute of the reconstructed object. It can be seen that, since the attributes of the object to be reconstructed are not required to be obtained by reflection in the embodiment of the present application, it is not necessary to occupy excessive hardware resources, thereby improving the efficiency of deserialization.
  • the present application since the present application does not need to obtain the attribute of the object to be reconstructed by means of reflection, there is no longer a problem that the programming language does not support, so that the method embodiment of the present application is applicable to many different programming languages, such as Java and C#. .
  • the application first generates the first key value pair according to the deserialization data, and then assigns the first attribute according to the first key value pair, even if the serialized data has different formats, for example, The xml format is also the json format, and only the same program can be used to implement the assignment of the first attribute.
  • the deserialized data may also be obtained by calling an application programming interface (English: Application Programming Interface, API for short).
  • the 101 in this embodiment includes: calling an API corresponding to the object to be reconstructed; acquiring return data calling the API, and using the returned data as the serialized data.
  • the object to be reconstructed may have at least two attributes, and the serialized data may be parsed in 102 to generate a key value pair list, where the key value pair list includes at least two key value pairs, each key The key information and the value information in the value pair have a corresponding relationship, and the key information in the list is searched for the corresponding value information in the key value pair and assigned to the corresponding attribute of the object to be reconstructed.
  • the following embodiment is described by taking two attributes of the object to be reconstructed as an example.
  • an embodiment of the present application provides another method embodiment of the deserialization method.
  • the embodiment includes:
  • serialized data can be data in json format:
  • the first attribute is the attribute “userID” and the second attribute is “userAddress”.
  • the serialized data further includes a first attribute value and a second attribute value, the first attribute has a corresponding relationship with the first attribute value, and the second attribute has a corresponding relationship with the second attribute value.
  • 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.
  • the second key value pair includes second key information and second value information, and the second key information has a corresponding relationship with the second value information.
  • the first key information is used to represent the first attribute
  • the first value information is used to represent the first attribute value.
  • the second key information is used to represent the second attribute, and the second value information is used to represent the second attribute value.
  • serialized data is data in json format:
  • the generated list of key-value pairs can be:
  • the User.userID is the first key information
  • 0001 is the first value information
  • User.userAddress is the second key information
  • address01 is the second value information.
  • the list of key-value pairs can be stored in a map object.
  • the 203 assign the first attribute to the first value information corresponding to the first key information according to a preset relationship between the first key information and the first attribute, and according to a preset And the corresponding relationship between the second key information and the second attribute, the second attribute is assigned to the second value information corresponding to the second key information.
  • the first key information is User.userID
  • the second key information is User.userAddress
  • you can assign "userAddress” to address01 corresponding to "User.userAddress”, that is, let userAddress address01.
  • the first key value pair is first generated according to the deserialization data, and the first attribute is assigned according to the first key value pair, instead of directly according to the Deserializing the data for assignment also has the technical effect of reducing the number of times the deserialized data is parsed.
  • the serialized data Data in json format if the serialized data Data in json format:
  • the object to be reconstructed has two attributes: userID and userAddress. If the first key-value pair is not generated and the two attributes are directly assigned, at least the deserialized data is parsed twice, and the first parsing is : matching the attribute userID with the deserialized data, so that the attribute value corresponding to the attribute userID is 0001, and the second parsing is: matching the attribute userAddress with the deserialized data, thereby obtaining the attribute userAddress corresponding to The attribute value is address01.
  • the deserialization method provided by the present application is used, no matter how many attributes of the object to be reconstructed, only the deserialized data needs to be parsed once to generate a list of key value pairs, and then according to the key value pair list. Each key value pair assigns an attribute of the object to be reconstructed. It can be seen that the application does not need to parse the data to be serialized multiple times, thereby reducing the workload.
  • the first attribute may be a simple type or a complex type, which is separately described below.
  • the deserialized data is data in json format:
  • userID is the direct attribute of the object user, so userID is a simple type.
  • the first attribute may be directly assigned to the first value information in 103.
  • the generated first key value pair can be:
  • the User.userID is the first key information, and 0001 is the first value information.
  • the first attribute can be assigned by the following Java code:
  • the above code indicates that the correspondence relationship between the first key information User.userID and the first attribute userID is set in advance.
  • the first key-value pair is stored in the map object.
  • the userID and User.userID are both string types, so there is no need to do type conversion. If User.userID is a string type and userID is another type, such as an int type, data conversion is required.
  • the first attribute can be assigned by the following Java code:
  • a complex type means that the first attribute has a sub-attribute.
  • the deserialized data is a number in json format according to:
  • vpcAttributes is the first attribute
  • NatIpAddress is a sub-attribute of the first attribute vpcAttributes.
  • the 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 The first attribute. And the assigning the first attribute to the first value information corresponding to the first key information according to the preset relationship between the first key information and the first attribute, including: The attribute of the first sub-object is assigned to the first value information corresponding to the first key information according to a preset relationship between the first key information and the sub-attribute.
  • the generated first key value pair may be:
  • the User.VpcAttributes.NatIpAddress is the first key information
  • the Address02 is the first value information.
  • the first key information corresponds to the first attribute and a sub-attribute of the first attribute.
  • the subobject vpcAttributes can be created with the following Java code:
  • VpcAttributes vpcAttributes new VpcAttributes();
  • vpcAttributes.setNatIpAddress (map.get("User.VpcAttributes.NatIpAddress"));
  • the above code indicates that the correspondence relationship between the first key information User.VpcAttributes.NatIpAddress and the sub-attribute NatIpAddress is set in advance.
  • the first attribute may also be a set format, and the first attribute may be assigned in a round-robin manner.
  • the method further includes: establishing a second sub-object of the object to be reconstructed, where the second sub-object is a set type; and assigning the first attribute to the first key information corresponding to The first value information includes: assigning, by a cyclic manner, the attribute of the second sub-object to the first value information corresponding to the first key information to obtain an attribute value of the second sub-object;
  • the first attribute is assigned to the attribute value of the second child object.
  • the collection format may be a list format, a Set format, or an array format.
  • the collection type can be a list type, a Set type, or an array type.
  • the deserialized data may be data in a josn format:
  • the InnerIpAddress is the first attribute, and the first attribute is a set format.
  • the generated first key value pair can be:
  • User.InnerIpAddress[0] is the first key information
  • 10.165.103.41 is the first value information.
  • the first key information can indicate that the first attribute is a set format, and can indicate that the first value information is located at a location of the first attribute of the set format.
  • User.InnerIpAddress[0] indicates that the first value information is the 0th bit of the first attribute.
  • the second sub-object innerIpAddress can be created by the following Java code:
  • the second sub-object innerIpAddress can be assigned the following Java code:
  • the first attribute can be assigned a value by the following Java code:
  • the present application also provides an embodiment of the deserialization device, which is specifically described below.
  • an embodiment of the present application provides an apparatus embodiment of a deserialization apparatus.
  • the embodiment includes an obtaining unit 301, a generating unit 302, and an assigning unit 303.
  • the obtaining unit 301 is configured to acquire serialized data, where the serialized data includes a first attribute of an object to be reconstructed.
  • the serialized data may be data in an xml format or a json format.
  • the serialized data further 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.
  • the generating unit 302 may parse the serialized data to generate the first key value pair, where the first key value pair includes first key information and first value information, the first The key information and the first value information have a corresponding relationship.
  • the first key information is used to represent the first attribute
  • the first value information is used to represent the first attribute value.
  • the assignment unit 303 is configured to assign the first attribute to the first value information corresponding to the first key information according to a correspondence between the first key information and the first attribute that are set in advance.
  • the present application since the object to be reconstructed has the first attribute being an intrinsic feature of the object to be reconstructed, the present application does not need to obtain the attribute of the object to be reconstructed by means of reflection, but may Presetting that the first attribute of the object to be reconstructed has a corresponding relationship with the first key information, and assigning the first attribute to the corresponding one of the first key information according to the corresponding relationship
  • the first value information may be regarded as a path of the attribute value of the first attribute, and the application actually uses the path to find the attribute value of the first attribute, that is, the first value information.
  • the first attribute is then assigned with the first value information.
  • the generating unit 302 parses the serialized data to generate a first key value pair, where the serialized data includes the object to be reconstructed.
  • An attribute, the first key value pair includes first key information and first value information having a corresponding relationship.
  • the object to be reconstructed has the intrinsic feature of the object to be reconstructed, and therefore, in the embodiment of the present application, the attribute of the object to be reconstructed is not required to be obtained by reflection, but the foregoing is set in advance.
  • the first attribute and the first key information have a corresponding relationship, so that the assigning unit 303 can assign the first attribute to the first value information corresponding to the first key information according to the corresponding relationship, and implement the pair Deserializing the first attribute of the object to be reconstructed. It can be seen that, since the attributes of the object to be reconstructed are not required to be obtained by reflection in the embodiment of the present application, it is not necessary to occupy excessive hardware resources, thereby improving the efficiency of deserialization.
  • the present application since the present application does not need to obtain the attributes of the object to be reconstructed by means of reflection, there is no longer a problem that the programming language does not support, so that the device embodiment of the present application is applicable to many different programming languages, such as Java and C#. .
  • the application first generates the first key value pair according to the deserialization data, and then assigns the first attribute according to the first key value pair, even if the serialized data has different formats, for example, The xml format is also the json format, and only the same program can be used to implement the assignment of the first attribute.
  • the deserialization data may also be obtained by calling an API.
  • the obtaining unit 301 in this embodiment is specifically configured to: invoke an API corresponding to the object to be reconstructed; acquire return data that invokes the API, and use the returned data as the serialized data.
  • the object to be reconstructed may have at least two attributes, and the generating unit 302 may parse the serialized data to generate a key value pair list, where the key value pair list includes at least two key value pairs, each of which The key information and the value information in the key value pair have a corresponding relationship, and the evaluation unit 303 searches for the corresponding value information through the key information in the key value pair list, and assigns the corresponding attribute to the object to be reconstructed.
  • the serialized data further includes a second attribute of the object to be reconstructed.
  • the serialized data further includes a second attribute value, and the second attribute has a corresponding relationship with the second attribute value.
  • the generating unit 302 is further configured to parse the serialized data to generate a second key value pair, the second key value pair includes second key information and second value information, the second key information and the The second value information has a corresponding relationship.
  • the second key information is used to represent the second attribute, and the second value information is used to represent the second attribute value.
  • the first key value pair and the second key value pair may constitute a key value pair list. In the Java language, the list of key-value pairs can be stored in a map object.
  • the assignment 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 relationship between the second key information and the second attribute.
  • the first key value pair is first generated according to the deserialization data, and the first attribute is assigned according to the first key value pair, instead of directly according to the Deserializing the data for assignment also has the technical effect of reducing the number of times the deserialized data is parsed.
  • the first attribute may be a simple type or a complex type, which is separately described below.
  • a simple type means that the first attribute does not have a sub-attribute, that is, the first attribute is a direct attribute of the object to be reconstructed.
  • the assignment unit 303 directly assigns the first attribute to the first value information.
  • a complex type means that the first attribute has a sub-attribute.
  • the apparatus in the embodiment of the present application may further include: a first establishing unit, where the first establishing unit is configured to establish the object to be reconstructed The first sub-object; the assignment unit 301 is configured to: assign the attribute of the first sub-object to the first key information according to the correspondence between the first key information and the sub-attribute The first value information.
  • the first attribute may also be a set format, and the first attribute may be assigned in a round-robin manner.
  • the first attribute is a set format
  • the apparatus of the embodiment of the present application further includes: a second establishing unit, where the second establishing unit is configured to establish a second sub-object of the object to be reconstructed, The second sub-object is a collection type; when the first attribute is assigned to the first value information corresponding to the first key information, the assignment unit 303 is specifically configured to: cyclically adopt the second sub-object The attribute is assigned to the first value information corresponding to the first key information to obtain an attribute value of the second sub-object; and the first attribute is assigned to an attribute value of the second sub-object.
  • the collection format may be a list format, a Set format, or an array format.
  • the collection type can be a list type, a Set type, or an array type.
  • the disclosed system, apparatus, and method may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • there may be another division manner for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be in an electrical, mechanical or other form.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware or in the 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 standalone product, may be stored in a computer readable storage medium.
  • a computer readable storage medium A number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present application.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like. .

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

一种反序列化方法及装置,所述方法包括:获取序列化数据(101),所述序列化数据包括待重建对象的第一属性;对所述序列化数据进行解析以生成第一键值对(102),所述第一键值对包括第一键信息和第一值信息,所述第一键信息与所述第一值信息具有对应关系;根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息(103)。该方法无需通过反射的方式获得待重建对象具有的属性,因此不需要占用过多的硬件资源,从而提高了反序列化的效率。

Description

一种反序列化方法及装置
本申请要求2015年07月13日递交的申请号为201510408889.1、发明名称为“一种反序列化方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机技术领域,尤其是涉及一种反序列化方法及装置。
背景技术
序列化和反序列化是计算机领域常用的技术。序列化用于将对象的属性值转换为序列化数据,从而能够对序列化数据进行保存或者传输等操作。反序列化为序列化的逆过程,用于对序列化数据解析获得对象的属性值,根据属性值对待重建对象的属性进行赋值。
举例说明,User是一个表示用户的类,user是一个User类的对象,user具有属性:userID,属性userID的属性值为0001。将user的属性值保存为序列化数据,例如xml格式或者json格式的数据的过程即为一种序列化,而从xml格式或者json格式的数据中解析出user的属性值,根据user的属性值对user的属性进行赋值的过程即为一种反序列化。
目前在实现反序列化时,首先要通过反射的方式获得待重建对象具有的属性,之后通过解析序列化数据获得属性对应的属性值,并根据获得的属性值对属性赋值。然而,目前在通过反射的方式获得所述待重建对象具有的属性时,通常会占用较多的硬件资源,从而造成反序列化的效率较低。
发明内容
本申请解决的技术问题在于提供一种反序列化方法及装置,无需通过反射的方式获得待重建对象具有的属性,从而节约了硬件资源以提高反序列化的效率。
为此,本申请解决技术问题的技术方案是:
本申请提供了一种反序列化方法,包括:
获取序列化数据,所述序列化数据包括待重建对象的第一属性;
对所述序列化数据进行解析以生成第一键值对,所述第一键值对包括第一键信息和第一值信息,所述第一键信息与所述第一值信息具有对应关系;
根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值 为所述第一键信息对应的所述第一值信息。
可选的,所述序列化数据还包括所述待重建对象的第二属性;所述方法还包括:
对所述序列化数据进行解析以生成第二键值对,所述第二键值对包括第二键信息和第二值信息,所述第二键信息与所述第二值信息具有对应关系;
根据预先设置的所述第二键信息和所述第二属性的对应关系,将所述第二属性赋值为所述第二键信息对应的所述第二值信息。
可选的,所述第一属性具有子属性;
所述方法还包括:建立所述待重建对象的第一子对象;
所述根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息,包括:
根据预先设置的所述第一键信息和所述子属性的对应关系,将所述第一子对象的属性赋值为所述第一键信息对应的所述第一值信息。
可选的,所述第一属性为集合格式;
所述方法还包括:建立所述待重建对象的第二子对象,所述第二子对象为集合类型;
将所述第一属性赋值为所述第一键信息对应的所述第一值信息,包括:
通过循环方式将所述第二子对象的属性赋值为所述第一键信息对应的所述第一值信息,以得到所述第二子对象的属性值;
将所述第一属性赋值为所述第二子对象的属性值。
可选的,所述获取序列化数据,包括:
调用与所述待重建对象对应的API;
获取调用所述API的返回数据,将所述返回数据作为所述序列化数据。
本申请还提供了一种反序列化装置,包括:
获取单元,用于获取序列化数据,所述序列化数据包括待重建对象的第一属性;
生成单元,用于对所述序列化数据进行解析以生成第一键值对,所述第一键值对包括第一键信息和第一值信息,所述第一键信息与所述第一值信息具有对应关系;
赋值单元,用于根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息。
可选的,所述序列化数据还包括所述待重建对象的第二属性;
所述生成单元还用于,对所述序列化数据进行解析以生成第二键值对,所述第二键值对包括第二键信息和第二值信息,所述第二键信息与所述第二值信息具有对应关系;
所述赋值单元还用于,根据预先设置的所述第二键信息和所述第二属性的对应关系,将所述第二属性赋值为所述第二键信息对应的所述第二值信息。
可选的,所述第一属性具有子属性;
所述装置还包括:第一建立单元,所述第一建立单元用于建立所述待重建对象的第一子对象;
所述赋值单元具体用于:
根据预先设置的所述第一键信息和所述子属性的对应关系,将所述第一子对象的属性赋值为所述第一键信息对应的所述第一值信息。
可选的,所述第一属性为集合格式;
所述装置还包括:第二建立单元,所述第二建立单元用于建立所述待重建对象的第二子对象,所述第二子对象为集合类型;
当将所述第一属性赋值为所述第一键信息对应的所述第一值信息,所述赋值单元具体用于:
通过循环方式将所述第二子对象的属性赋值为所述第一键信息对应的所述第一值信息,以得到所述第二子对象的属性值;
将所述第一属性赋值为所述第二子对象的属性值。
可选的,所述获取单元具体用于:
调用与所述待重建对象对应的API;
获取调用所述API的返回数据,将所述返回数据作为所述序列化数据。
通过上述技术方案可知,本申请实施例在获取序列化数据后,对所述序列化数据进行解析生成第一键值对,其中,所述序列化数据包括待重建对象的第一属性,所述第一键值对包括具有对应关系的第一键信息和第一值信息。其中,由于所述待重建对象具有所述第一属性是所述待重建对象的固有特征,因此本申请实施例中无需通过反射的方式获得待重建对象具有的属性,而是预先设置出所述第一属性和所述第一键信息具有对应关系,从而可以根据该对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息,实现了对所述待重建对象的所述第一属性的反序列化。可见,由于本申请实施例中无需通过反射的方式获得待重建对象具有的属性,因此不需要占用过多的硬件资源,从而提高了反序列化的效率。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,还可以根据这些附图获得其它的附图。
图1为本申请实施例提供的一种方法实施例的流程示意图;
图2为本申请实施例提供的另一种方法实施例的流程示意图;
图3为本申请实施例提供的一种装置实施例的结构示意图。
具体实施方式
下面通过一个例子对目前反序列化的方式进行说明。
User是一个表示用户的类,user是一个User类的对象,即User类的一个实例,user具有属性:userID,属性userID的属性值为0001,通过序列化将user的属性值0001转换为序列化数据,例如json格式的数据:{“userID”:“0001”}
反序列化的过程是:首先通过反射的方式获得user具有的属性:userID,之后通过解析序列化数据获得属性对应的属性值,例如,将通过反射获得的属性userID与序列化数据进行匹配,从而获得属性userID对应的属性值为0001,再根据获得的属性值0001对属性userID赋值,即实现对属性userID的反序列化。当对user的所有属性均进行赋值后,即实现重建对象user。
然而,在通过反射方式获得user具有的属性时,通常会占用较多的硬件资源,从而造成反序列化的效率较低。
此外,这种方式还具有以下问题:由于一些编程语言并不支持通过反射方式获得待重建对象具有的属性,从而可能导致无法实现反序列化;由于序列化数据可能存在多种格式,例如xml格式或者json格式,因此针对于不同的格式需要编写不同的程序代码对待重建对象的属性进行赋值。
本申请实施例提供一种反序列化方法及装置,无需通过反射的方式获得待重建对象具有的属性,从而节约了硬件资源以提高反序列化的效率。
为了使本技术领域的人员更好地理解本申请中的技术方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都应当属于本申请保护的范围。
请参阅图1,本申请实施例提供了反序列化方法的一种方法实施例,本实施例包括:
101:获取序列化数据,所述序列化数据包括待重建对象的第一属性。
本申请实施例中,所述序列化数据可以为xml格式或者json格式的数据。例如,所述序列化数据可以为json格式的数据:
{“userID”:“0001”}
其中,userID为所述第一属性。
所述序列化数据还包括第一属性值,所述第一属性与所述第一属性值具有对应关系。
102:对所述序列化数据进行解析以生成第一键值对。
在本申请实施例中,可以对所述序列化数据进行解析生成所述第一键值对,所述第一键值对包括第一键信息(Key)和第一值信息(Value),所述第一键信息和所述第一值信息具有对应关系。其中,所述第一键信息用于表示所述第一属性,所述第一值信息用于表示所述第一属性值。
举例说明,若所述序列化数据为json格式的数据:
{“userID”:“0001”}
生成的所述第一键值对可以为:
{User.userID=0001}
其中,User.userID为所述第一键信息,0001为所述第一值信息。
103:根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息。
在本申请实施例中,由于所述待重建对象具有所述第一属性是所述待重建对象的固有特征,因此本申请无需通过反射的方式获得所述待重建对象具有的属性,而是可以预先设置出所述待重建对象具有的所述第一属性与所述第一键信息具有对应关系,并根据该对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息。其中,所述第一键信息可以看作是所述第一属性的属性值的路径,本申请实际上利用该路径,查找到所述第一属性的属性值,即所述第一值信息,从而利用所述第一值信息对所述第一属性进行赋值。
举例说明,若所述第一键信息为:User.userID=0001,预先设置所述第一属性userID和所述第一键信息User.userID具有对应关系,因此可以将userID赋值为User.userID对应的0001,即令userID=0001。
通过上述技术方案可知,本申请实施例在获取序列化数据后,对所述序列化数据进 行解析生成第一键值对,其中,所述序列化数据包括待重建对象的第一属性,所述第一键值对包括具有对应关系的第一键信息和第一值信息。其中,由于所述待重建对象具有所述第一属性是所述待重建对象的固有特征,因此本申请实施例中无需通过反射的方式获得待重建对象具有的属性,而是预先设置出所述第一属性和所述第一键信息具有对应关系,从而可以根据该对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息,实现了对所述待重建对象的所述第一属性的反序列化。可见,由于本申请实施例中无需通过反射的方式获得待重建对象具有的属性,因此不需要占用过多的硬件资源,从而提高了反序列化的效率。
此外,由于本申请无需通过反射的方式获得待重建对象具有的属性,因此不再存在编程语言不支持的问题,使得本申请的方法实施例适用于多种不同的编程语言,例如Java以及C#等。而且本申请首先根据反序列化数据生成所述第一键值对,再根据所述第一键值对对所述第一属性进行赋值,即使所述序列化数据存在不同的格式,例如无论是xml格式还是json格式,也只需同一种程序即可实现对所述第一属性的赋值。
在本申请实施例中,还可以通过调用应用程序编程接口(英文:Application Programming Interface,简称:API)的方式获得所述反序列化数据。具体地,本实施例中的101包括:调用与所述待重建对象对应的API;获取调用所述API的返回数据,将所述返回数据作为所述序列化数据。
在上述实施例中,只介绍了对所述第一属性的反序列化过程,若所述待重建对象还包括除所述第一属性之外的其他属性,可以按照类似方式对其他属性进行反序列化。例如,所述待重建对象可以具有至少两个属性,则102中可以对所述序列化数据进行解析生成键值对列表,所述键值对列表中包括至少两个键值对,每个键值对中的键信息和值信息具有对应关系,103中通过键值对列表中的键信息查找相应的值信息,并赋值给所述待重建对象的相应的属性。下面的实施例以所述待重建对象包括两个属性为例进行说明。
请参阅图2,本申请实施例提供了反序列化方法的另一种方法实施例,本实施例包括:
201:获取序列化数据,所述序列化数据包括待重建对象的第一属性和第二属性。
例如,所述序列化数据可以为json格式的数据:
{“userID”:“0001”,
“userAddress”:“address01”}
其中,所述第一属性为属性“userID”,所述第二属性为“userAddress”。
所述序列化数据还包括第一属性值和第二属性值,所述第一属性与所述第一属性值具有对应关系,所述第二属性与所述第二属性值具有对应关系。
202:对所述序列化数据进行解析以生成键值对列表,所述键值对列表包括第一键值对和第二键值对。
所述第一键值对包括第一键信息和第一值信息,第一键信息和第一值信息具有对应关系。所述第二键值对包括第二键信息和第二值信息,所述第二键信息与所述第二值信息具有对应关系。其中,所述第一键信息用于表示所述第一属性,所述第一值信息用于表示所述第一属性值。所述第二键信息用于表示所述第二属性,所述第二值信息用于表示所述第二属性值。
举例说明,若所述序列化数据为json格式的数据:
{“userID”:“0001”,“userAddress”:“address01”}
生成的所述键值对列表可以为:
{User.userID=0001,User.userAddress=address01}
其中,User.userID为所述第一键信息,0001为所述第一值信息,User.userAddress为所述第二键信息,address01为所述第二值信息。
在java语言中,所述键值对列表可以存储到map对象里。
203:根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息,并且根据预先设置的所述第二键信息和所述第二属性的对应关系,将所述第二属性赋值为所述第二键信息对应的所述第二值信息。
举例说明,若所述第一键信息为User.userID,所述第二键信息为User.userAddress,预先设置所述第一属性“userID”和所述第一键信息“User.userID”具有对应关系,并且预先设置所述第二属性“userAddress”和所述第二键信息“User.userAddress”具有对应关系,因此可以将“userID”赋值为“User.userID”对应的0001,即令userID=0001,并且可以将“userAddress”赋值为“User.userAddress”对应的address01,即令userAddress=address01。
还需说明的是,本申请中先根据所述反序列化数据生成所述第一键值对,再根据所述第一键值对对所述第一属性进行赋值,而不是直接根据所述反序列化数据进行赋值,还具有减少对所述反序列化数据的解析次数的技术效果。举例说明,若所述序列化数据 为json格式的数据:
{“userID”:“0001”,
“userAddress”:“address01”}
待重建对象具有两个属性:userID和userAddress,若不生成所述第一键值对而直接对这两个属性进行赋值,则至少对所述反序列化数据解析两次,第一次解析为:将属性userID与所述反序列化数据进行匹配,从而获得属性userID对应的属性值为0001,第二次解析为:将属性userAddress与所述反序列化数据进行匹配,从而获得属性userAddress对应的属性值为address01。而如果采用本申请提供的反序列化方法,无论所述待重建对象具有多少个属性,只需对所述反序列化数据解析一次以生成键值对列表,之后根据所述键值对列表中的各个键值对对所述待重建对象的属性进行赋值。可见本申请无需对所述待序列化数据进行多次解析,从而减少了工作量。
在本申请实施例中,所述第一属性可以为简单类型,也可以为复杂类型,下面分别说明。
简单类型指的是所述第一属性不具有子属性,即所述第一属性为所述待重建对象的直接属性。例如所述反序列化数据为json格式的数据:
{“userID”:“0001”}
其中,userID为对象user的直接属性,因此userID属于简单类型。
对于简单类型,103中直接将所述第一属性赋值为所述第一值信息即可。
例如,生成的所述第一键值对可以为:
{User.userID=0001}
其中,User.userID为所述第一键信息,0001为所述第一值信息。
可以通过以下Java代码对所述第一属性进行赋值:
user.setuserID(map.get("User.userID"));
上述代码表示出预先设置了第一键信息User.userID和所述第一属性userID的对应关系。map对象中存储有所述第一键值对。
并且在上述代码中,表示userID和User.userID均为字符串类型,因此无需作类型转换。如果User.userID为字符串类型,userID为其他类型,例如int类型,则需要进行数据转换,具体可以通过以下Java代码对所述第一属性进行赋值:
user.setUserID(Integer.valueOf(map.get("User.userID")));
复杂类型指的是所述第一属性具有子属性。例如所述反序列化数据为json格式的数 据:
{"vpcAttributes":{"NatIpAddress":"Address02"},
其中,vpcAttributes为所述第一属性,NatIpAddress为所述第一属性vpcAttributes的子属性。
在本申请实施例中,若所述第一属性为复杂类型,则本申请实施例还可以包括:建立所述待重建对象的第一子对象;其中所述第一子对象实际上为所述第一属性。103中的所述根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息,包括:根据预先设置的所述第一键信息和所述子属性的对应关系,将所述第一子对象的属性赋值为所述第一键信息对应的所述第一值信息。下面举例说明。
仍以上述json格式的数据为例,生成的所述第一键值对可以为:
{User.VpcAttributes.NatIpAddress=Address02}
其中,User.VpcAttributes.NatIpAddress为所述第一键信息,Address02为所述第一值信息。其中所述第一键信息对应所述第一属性和所述第一属性的子属性。
可以通过以下Java代码建立子对象vpcAttributes:
VpcAttributes vpcAttributes=new VpcAttributes();
可以通过以下Java代码对子对象vpcAttributes的属性进行赋值:
vpcAttributes.setNatIpAddress(map.get("User.VpcAttributes.NatIpAddress"));上述代码表示出预先设置了第一键信息User.VpcAttributes.NatIpAddress和子属性NatIpAddress的对应关系。
在本申请实施例中,所述第一属性还可以为集合格式,此时可以通过循环方式对所述第一属性进行赋值。具体地,所述方法还包括:建立所述待重建对象的第二子对象,所述第二子对象为集合类型;103中的将所述第一属性赋值为所述第一键信息对应的所述第一值信息,包括:通过循环方式将所述第二子对象的属性赋值为所述第一键信息对应的所述第一值信息,以获得所述第二子对象的属性值;将所述第一属性赋值为第二子对象的属性值。其中,集合格式可以为list格式、Set格式或者数组格式等。集合类型可以为list类型、Set类型或者数组类型等。
下面举例说明上述循环赋值方式。
所述反序列化数据可以为josn格式的数据:
{"InnerIpAddress":
["10.165.103.41","10.165.103.42"]}
其中,InnerIpAddress为所述第一属性,所述第一属性为集合格式。
生成的所述第一键值对可以为:
{User.InnerIpAddress[0]=10.165.103.41}
其中,User.InnerIpAddress[0]为所述第一键信息,10.165.103.41为所述第一值信息。其中,所述第一键信息能够表示出所述第一属性为集合格式,并且能够表示出所述第一值信息位于所述集合格式的所述第一属性的位置。例如User.InnerIpAddress[0]表示所述第一值信息为所述第一属性的第0位。
可以通过以下Java代码建立第二子对象innerIpAddress:
List<String>innerIpAddress=new ArrayList<String>();
可以通过以下Java代码对第二子对象innerIpAddress赋值:
for(int i=0;i<Integer.valueOf(map.get("User.InnerIpAddress.Length"));i++){
innerIpAddress.add(map.get("User.InnerIpAddress["+i+"]"));
}
可以通过以下Java代码对所述第一属性赋值:
user.setInnerIpAddress(innerIpAddress);
其中,user为所述待重建对象。
对应与上述方法实施例,本申请还提供了反序列化装置的实施例,下面具体说明。
请参阅图3,本申请实施例提供了反序列化装置的一种装置实施例,本实施例包括:获取单元301、生成单元302和赋值单元303。
获取单元301用于获取序列化数据,所述序列化数据包括待重建对象的第一属性。
本申请实施例,所述序列化数据可以为xml格式或者json格式的数据。
所述序列化数据还包括第一属性值,所述第一属性与所述第一属性值具有对应关系。
生成单元302用于对所述序列化数据进行解析以生成第一键值对。
在本申请实施例中,生成单元302可以对所述序列化数据进行解析生成所述第一键值对,所述第一键值对包括第一键信息和第一值信息,所述第一键信息和所述第一值信息具有对应关系。其中,所述第一键信息用于表示所述第一属性,所述第一值信息用于表示所述第一属性值。
赋值单元303用于根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息。
在本申请实施例中,由于所述待重建对象具有所述第一属性是所述待重建对象的固有特征,因此本申请无需通过反射的方式获得所述待重建对象具有的属性,而是可以预先设置出所述待重建对象具有的所述第一属性与所述第一键信息具有对应关系,并根据该对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息。其中,所述第一键信息可以看作是所述第一属性的属性值的路径,本申请实际上利用该路径,查找到所述第一属性的属性值,即所述第一值信息,从而利用所述第一值信息对所述第一属性进行赋值。
通过上述技术方案可知,本申请实施例获取单元301获取序列化数据后,生成单元302对所述序列化数据进行解析生成第一键值对,其中,所述序列化数据包括待重建对象的第一属性,所述第一键值对包括具有对应关系的第一键信息和第一值信息。其中,由于所述待重建对象具有所述第一属性是所述待重建对象的固有特征,因此本申请实施例中无需通过反射的方式获得待重建对象具有的属性,而是预先设置出所述第一属性和所述第一键信息具有对应关系,从而赋值单元303可以根据该对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息,实现了对所述待重建对象的所述第一属性的反序列化。可见,由于本申请实施例中无需通过反射的方式获得待重建对象具有的属性,因此不需要占用过多的硬件资源,从而提高了反序列化的效率。
此外,由于本申请无需通过反射的方式获得待重建对象具有的属性,因此不再存在编程语言不支持的问题,使得本申请的装置实施例适用于多种不同的编程语言,例如Java以及C#等。而且本申请首先根据反序列化数据生成所述第一键值对,再根据所述第一键值对对所述第一属性进行赋值,即使所述序列化数据存在不同的格式,例如无论是xml格式还是json格式,也只需同一种程序即可实现对所述第一属性的赋值。
在本申请实施例中,还可以通过调用API的方式获得所述反序列化数据。具体地,本实施例中的获取单元301具体用于:调用与所述待重建对象对应的API;获取调用所述API的返回数据,将所述返回数据作为所述序列化数据。
在上述实施例中,只介绍了对所述第一属性的反序列化过程,若所述待重建对象还包括除所述第一属性之外的其他属性,可以按照类似方式对其他属性进行反序列化。例如,所述待重建对象可以具有至少两个属性,则生成单元302可以对所述序列化数据进行解析生成键值对列表,所述键值对列表中包括至少两个键值对,每个键值对中的键信息和值信息具有对应关系,赋值单元303通过键值对列表中的键信息查找相应的值信息,并赋值给所述待重建对象的相应的属性。
例如,所述序列化数据还包括所述待重建对象的第二属性。其中,所述序列化数据还包括第二属性值,所述第二属性与所述第二属性值具有对应关系。
生成单元302还用于,对所述序列化数据进行解析以生成第二键值对,所述第二键值对包括第二键信息和第二值信息,所述第二键信息与所述第二值信息具有对应关系。所述第二键信息用于表示所述第二属性,所述第二值信息用于表示所述第二属性值。所述第一键值对和所述第二键值对可以构成键值对列表。在java语言中,所述键值对列表可以存储到map对象里。
赋值单元303还用于,根据预先设置的所述第二键信息和所述第二属性的对应关系,将所述第二属性赋值为所述第二键信息对应的所述第二值信息。
还需说明的是,本申请中先根据所述反序列化数据生成所述第一键值对,再根据所述第一键值对对所述第一属性进行赋值,而不是直接根据所述反序列化数据进行赋值,还具有减少对所述反序列化数据的解析次数的技术效果。
在本申请实施例中,所述第一属性可以为简单类型,也可以为复杂类型,下面分别说明。
简单类型指的是所述第一属性不具有子属性,即所述第一属性为所述待重建对象的直接属性。对于简单类型,赋值单元303直接将所述第一属性赋值为所述第一值信息即可。
复杂类型指的是所述第一属性具有子属性。在本申请实施例中,若所述第一属性为复杂类型,则本申请实施例的所述装置还可以包括:第一建立单元,所述第一建立单元用于建立所述待重建对象的第一子对象;赋值单元301具体用于:根据预先设置的所述第一键信息和所述子属性的对应关系,将所述第一子对象的属性赋值为所述第一键信息对应的所述第一值信息。
在本申请实施例中,所述第一属性还可以为集合格式,此时可以通过循环方式对所述第一属性进行赋值。具体地,所述第一属性为集合格式;本申请实施例的所述装置还包括:第二建立单元,所述第二建立单元用于建立所述待重建对象的第二子对象,所述第二子对象为集合类型;当将所述第一属性赋值为所述第一键信息对应的所述第一值信息,赋值单元303具体用于:通过循环方式将所述第二子对象的属性赋值为所述第一键信息对应的所述第一值信息,以得到所述第二子对象的属性值;将所述第一属性赋值为所述第二子对象的属性值。其中,集合格式可以为list格式、Set格式或者数组格式等。集合类型可以为list类型、Set类型或者数组类型等。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。

Claims (10)

  1. 一种反序列化方法,其特征在于,包括:
    获取序列化数据,所述序列化数据包括待重建对象的第一属性;
    对所述序列化数据进行解析以生成第一键值对,所述第一键值对包括第一键信息和第一值信息,所述第一键信息与所述第一值信息具有对应关系;
    根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息。
  2. 根据权利要求1所述的方法,其特征在于,所述序列化数据还包括所述待重建对象的第二属性;所述方法还包括:
    对所述序列化数据进行解析以生成第二键值对,所述第二键值对包括第二键信息和第二值信息,所述第二键信息与所述第二值信息具有对应关系;
    根据预先设置的所述第二键信息和所述第二属性的对应关系,将所述第二属性赋值为所述第二键信息对应的所述第二值信息。
  3. 根据权利要求1所述的方法,其特征在于,所述第一属性具有子属性;
    所述方法还包括:建立所述待重建对象的第一子对象;
    所述根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息,包括:
    根据预先设置的所述第一键信息和所述子属性的对应关系,将所述第一子对象的属性赋值为所述第一键信息对应的所述第一值信息。
  4. 根据权利要求1所述的方法,其特征在于,所述第一属性为集合格式;
    所述方法还包括:建立所述待重建对象的第二子对象,所述第二子对象为集合类型;
    将所述第一属性赋值为所述第一键信息对应的所述第一值信息,包括:
    通过循环方式将所述第二子对象的属性赋值为所述第一键信息对应的所述第一值信息,以得到所述第二子对象的属性值;
    将所述第一属性赋值为所述第二子对象的属性值。
  5. 根据权利要求1至4任一项所述的方法,其特征在于,所述获取序列化数据,包括:
    调用与所述待重建对象对应的API;
    获取调用所述API的返回数据,将所述返回数据作为所述序列化数据。
  6. 一种反序列化装置,其特征在于,包括:
    获取单元,用于获取序列化数据,所述序列化数据包括待重建对象的第一属性;
    生成单元,用于对所述序列化数据进行解析以生成第一键值对,所述第一键值对包括第一键信息和第一值信息,所述第一键信息与所述第一值信息具有对应关系;
    赋值单元,用于根据预先设置的所述第一键信息和所述第一属性的对应关系,将所述第一属性赋值为所述第一键信息对应的所述第一值信息。
  7. 根据权利要求6所述的装置,其特征在于,所述序列化数据还包括所述待重建对象的第二属性;
    所述生成单元还用于,对所述序列化数据进行解析以生成第二键值对,所述第二键值对包括第二键信息和第二值信息,所述第二键信息与所述第二值信息具有对应关系;
    所述赋值单元还用于,根据预先设置的所述第二键信息和所述第二属性的对应关系,将所述第二属性赋值为所述第二键信息对应的所述第二值信息。
  8. 根据权利要求6所述的装置,其特征在于,所述第一属性具有子属性;
    所述装置还包括:第一建立单元,所述第一建立单元用于建立所述待重建对象的第一子对象;
    所述赋值单元具体用于:
    根据预先设置的所述第一键信息和所述子属性的对应关系,将所述第一子对象的属性赋值为所述第一键信息对应的所述第一值信息。
  9. 根据权利要求6所述的装置,其特征在于,所述第一属性为集合格式;
    所述装置还包括:第二建立单元,所述第二建立单元用于建立所述待重建对象的第二子对象,所述第二子对象为集合类型;
    当将所述第一属性赋值为所述第一键信息对应的所述第一值信息,所述赋值单元具体用于:
    通过循环方式将所述第二子对象的属性赋值为所述第一键信息对应的所述第一值信息,以得到所述第二子对象的属性值;
    将所述第一属性赋值为所述第二子对象的属性值。
  10. 根据权利要求6至9任一项所述的装置,其特征在于,所述获取单元具体用于:
    调用与所述待重建对象对应的API;
    获取调用所述API的返回数据,将所述返回数据作为所述序列化数据。
PCT/CN2016/088324 2015-07-13 2016-07-04 一种反序列化方法及装置 WO2017008654A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510408889.1 2015-07-13
CN201510408889.1A CN107038022B (zh) 2015-07-13 2015-07-13 一种反序列化方法及装置

Publications (1)

Publication Number Publication Date
WO2017008654A1 true WO2017008654A1 (zh) 2017-01-19

Family

ID=57756802

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/088324 WO2017008654A1 (zh) 2015-07-13 2016-07-04 一种反序列化方法及装置

Country Status (2)

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

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
DE102018208702A1 (de) 2018-06-01 2019-12-05 Volkswagen Aktiengesellschaft Verkleidungsteil, Verfahren und Vorrichtung zum Herstellen eines Verkleidungsteils

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109871519A (zh) * 2019-02-18 2019-06-11 北京思特奇信息技术股份有限公司 一种无层级结构的json反序列化方法、装置及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090327225A1 (en) * 2008-06-26 2009-12-31 Microsoft Corporation Relationship serialization and reconstruction for entities
CN101661391A (zh) * 2009-09-24 2010-03-03 金蝶软件(中国)有限公司 一种对象序列化方法、对象反序列化方法、装置及系统
CN102750268A (zh) * 2012-06-19 2012-10-24 山东中创软件商用中间件股份有限公司 一种对象序列化方法、对象反序列化方法、装置及系统
CN103605518A (zh) * 2013-11-19 2014-02-26 北京国双科技有限公司 对象反序列化方法和装置
CN104360865A (zh) * 2014-11-28 2015-02-18 中国建设银行股份有限公司 一种序列化方法、反序列化方法及相关设备

Family Cites Families (3)

* 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
JP6044960B2 (ja) * 2013-12-26 2016-12-14 インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation シリアライザを特化する方法、装置及びコンピュータプログラム
CN104360862A (zh) * 2014-11-20 2015-02-18 浪潮通用软件有限公司 Net平台下基于属性标签和配置文件的Xml序列化模型实现方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090327225A1 (en) * 2008-06-26 2009-12-31 Microsoft Corporation Relationship serialization and reconstruction for entities
CN101661391A (zh) * 2009-09-24 2010-03-03 金蝶软件(中国)有限公司 一种对象序列化方法、对象反序列化方法、装置及系统
CN102750268A (zh) * 2012-06-19 2012-10-24 山东中创软件商用中间件股份有限公司 一种对象序列化方法、对象反序列化方法、装置及系统
CN103605518A (zh) * 2013-11-19 2014-02-26 北京国双科技有限公司 对象反序列化方法和装置
CN104360865A (zh) * 2014-11-28 2015-02-18 中国建设银行股份有限公司 一种序列化方法、反序列化方法及相关设备

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
DE102018208702A1 (de) 2018-06-01 2019-12-05 Volkswagen Aktiengesellschaft Verkleidungsteil, Verfahren und Vorrichtung zum Herstellen eines Verkleidungsteils

Also Published As

Publication number Publication date
CN107038022B (zh) 2021-01-29
CN107038022A (zh) 2017-08-11

Similar Documents

Publication Publication Date Title
US9456229B2 (en) Parsing single source content for multi-channel publishing
US10282664B2 (en) Method and device for constructing event knowledge base
US20180084063A1 (en) Systems and methods for selecting efficient messaging between services
US9858299B2 (en) System and method for generating a JSON schema from a JSON stream
US20110276603A1 (en) Dependency graphs for multiple domains
US8645502B2 (en) Dynamic interface to read database through remote procedure call
JP6016808B2 (ja) Webアクセスを実装するための方法およびサーバシステム
JP5677319B2 (ja) ウェブに基づくダイアグラム視覚性の拡張性
US20190324760A1 (en) Transaction Processing Method and Apparatus
KR102589876B1 (ko) 단계 지원 작업 흐름을 위한 방법 및 장치
WO2017031894A1 (zh) 数据的搜索方法、装置及终端
CN110109983B (zh) 一种操作Redis数据库的方法和装置
WO2017008654A1 (zh) 一种反序列化方法及装置
US20080098373A1 (en) Processing an xml feed with extensible or non-typed elements
CN110888972A (zh) 一种基于Spark Streaming的敏感内容识别方法及装置
CN110941655B (zh) 一种数据格式转换方法及装置
CN112883088B (zh) 一种数据处理方法、装置、设备及存储介质
CN112579676A (zh) 异构系统间的数据处理方法、装置、存储介质和设备
KR102636992B1 (ko) 클라우드 서비스를 위한 방법 및 장치
CN113448985A (zh) 一种api接口生成方法、调用方法、装置及电子设备
CN107644103A (zh) 一种可追溯信息来源的信息存储的方法和系统
US20180046656A1 (en) Constructing filterable hierarchy based on multidimensional key
WO2020006930A1 (zh) 数据伪造方法、装置及计算机存储介质
CN113326305A (zh) 一种处理数据的方法和装置
Holzschuher et al. Performance optimization for querying social network data.

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16823801

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16823801

Country of ref document: EP

Kind code of ref document: A1