CN117973322A - Serialization method and device, deserialization method and device, and computer equipment - Google Patents

Serialization method and device, deserialization method and device, and computer equipment Download PDF

Info

Publication number
CN117973322A
CN117973322A CN202311451105.4A CN202311451105A CN117973322A CN 117973322 A CN117973322 A CN 117973322A CN 202311451105 A CN202311451105 A CN 202311451105A CN 117973322 A CN117973322 A CN 117973322A
Authority
CN
China
Prior art keywords
data
type
serialized
serialization
identifier
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.)
Pending
Application number
CN202311451105.4A
Other languages
Chinese (zh)
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.)
Mashang Consumer Finance Co Ltd
Original Assignee
Mashang Consumer Finance Co 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 Mashang Consumer Finance Co Ltd filed Critical Mashang Consumer Finance Co Ltd
Priority to CN202311451105.4A priority Critical patent/CN117973322A/en
Publication of CN117973322A publication Critical patent/CN117973322A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/151Transformation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present application relates to a serialization method and apparatus, a deserialization method and apparatus, a computer device, and a computer-readable storage medium. The serialization method comprises the following steps: acquiring a data object to be serialized and a data type to which the data object belongs; determining a target character identifier corresponding to the data type of the data object; carrying out serialization processing on the data object according to the data type of the data object to obtain a serialized object of the data object; and obtaining the serialized text data corresponding to the data object according to the target character identifier and the serialized object. The data objects of different types are represented by the single target character identifier, then the data objects are subjected to serialization processing according to the different character identifiers, so that the serialized objects are obtained, the serialization rule is relatively simple, and the efficiency of the serialization process is improved.

Description

Serialization method and device, deserialization method and device, and computer equipment
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a serialization method and apparatus, an anti-serialization method and apparatus, and a computer device.
Background
In the field of data processing in the computer technology, serialization refers to the process of converting a data structure or object state into a usable format to facilitate the recovery of the original state in the same or another computer environment. When the byte results are retrieved in a serialized format, it can be used to produce a copy of the same semantics as the original object. The reverse operation of extracting a data structure from a series of bytes is reverse serialization.
Taking the example of Java object serialization, when a Java object needs to be converted into a JSON (JavaScript Object Notation, a lightweight data interchange format) string, jackson will traverse the fields of the Java object and then convert them into the corresponding attributes and values in JSON format. However, this serialization method is complex, resulting in a less efficient serialization process.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a serialization method and apparatus, a deserialization method and apparatus, a computer device, a computer-readable storage medium, and a computer program product that can improve the serialization efficiency.
In a first aspect, an embodiment of the present application provides a serialization method, including:
Acquiring a data object to be serialized and a data type to which the data object belongs;
Determining a target character identifier corresponding to the data type of the data object;
carrying out serialization processing on the data object according to the data type of the data object to obtain a serialized object of the data object;
And obtaining the serialized text data corresponding to the data object according to the target character identifier and the serialized object.
According to the serialization method, the data object to be serialized and the data type to which the data object belongs are obtained, then the target character identifier corresponding to the data type to which the data object belongs is determined, then serialization processing is carried out on the data object based on the target character identifier to obtain the serialized object, finally the serialized text data corresponding to the data object is obtained according to the target character identifier and the serialized object, different types of data objects are represented through a single target character identifier, then serialization processing is carried out on the data object according to different character identifiers to obtain the serialized object, the serialization rule is relatively simple, and the efficiency of the serialization process is improved. In addition, the single character identifier and the serialized text representation are adopted, so that the readability is high.
In a second aspect, an embodiment of the present application provides a reverse serialization method, including:
Acquiring serialized text data;
Analyzing the serialized text data to obtain a target character identifier;
Determining a data type corresponding to the serialized text data according to the target character identifier;
and performing deserialization processing on the serialized text data based on the data type to obtain a corresponding data object.
According to the anti-serialization method provided by the embodiment of the application, the serialized text data is acquired, analyzed to obtain the target character identifier, and then the data object is subjected to anti-serialization processing based on the target character identifier to obtain the data object, so that the efficiency of the serialization process is improved due to relatively simple serialization rules, and the corresponding anti-serialization process is relatively simple, so that the efficiency of the anti-serialization process is improved.
In a third aspect, an embodiment of the present application provides a serialization apparatus, including:
the first acquisition module is used for acquiring a data object to be serialized and a data type to which the data object belongs;
The first determining module is used for determining a target character identifier corresponding to the data type of the data object;
The serialization module is used for carrying out serialization processing on the data object according to the data type of the data object to obtain a serialized object of the data object;
And the processing module is used for obtaining the serialized text data corresponding to the data object according to the target character identifier and the serialized object.
In a fourth aspect, an embodiment of the present application provides an anti-serialization apparatus, including:
The second acquisition module is used for acquiring the serialized text data;
the analysis module is used for analyzing the serialized text data to obtain a target character identifier;
The second determining module is used for determining the data type corresponding to the serialized text data according to the target character identifier;
And the deserializing module is used for deserializing the serialized text data based on the data type to obtain a data object.
In a fifth aspect, an embodiment of the present application provides a computer device comprising a memory storing a computer program and a processor implementing the steps of the method in the first or second aspect when the processor executes the computer program.
In a sixth aspect, embodiments of the present application provide a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of the method in the first or second aspect.
In a seventh aspect, embodiments of the present application provide a computer program product comprising a computer program which, when executed by a processor, implements the steps of the method of the first or second aspect.
Drawings
FIG. 1 is a diagram of an application environment for a serialization or deserialization method in one embodiment;
FIG. 2 is a flow diagram of a serialization method in one embodiment;
FIG. 3 is a flow chart of a serialization method in another embodiment;
FIG. 4 is a flow diagram of a method of deserializing in one embodiment;
FIG. 5 is a flow chart of a method of deserializing in another embodiment;
FIG. 6 is a schematic diagram of a serialization apparatus in one embodiment;
FIG. 7 is a schematic diagram of an anti-serialization apparatus according to an embodiment;
fig. 8 is an internal structural diagram of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
In the data processing of the computer domain, serialization (serialization) refers to the process of converting a data structure or object state into a usable format (e.g., storing a file, buffering, or transmitting over a network) to allow for subsequent recovery of the original state in the same or another computer environment. When the byte results are retrieved in a serialized format, it can be used to produce a copy of the same semantics as the original object. For many objects, such as complex objects that use a large number of references, this process of serialized reconstruction is not easy. Object serialization in object-oriented, which does not summarize functions that were previously related to the original object, is also known as object marshaling. Deserialization (deserialization or unmarshalling), also known as ungrouping, is the reverse operation of extracting a data structure from a series of bytes.
JSON (JavaScript Object Notation), a lightweight data exchange format. It stores and presents data in a text format that is completely independent of the programming language based on a subset of ECMAScript (European Computer Manufacturers Association, js specification by the european computer institute). The compact and clear hierarchical structure makes JSON an ideal data exchange language. Is easy to read and write by people, is easy to analyze and generate by machines, and effectively improves the network transmission efficiency.
XML (eXtensible Markup Language ), a data format designed to transmit, store, display data. And the method can also be used for marking data and defining data types, and is a source language which allows a user to define the marking language of the user.
ProtoBuf (Protocol Buffers), google corporation developed a way to sequence data structures across languages and platforms, is a flexible, efficient protocol for serializing data. ProtoBuf is smaller, faster, and more convenient than XML and JSON formats. ProtoBuf is cross-language and is provided with a compiler (protoc), and can be compiled into Java, python, C ++, C#, go and other multi-language codes only by compiling with protoc, and then can be directly used without writing other codes and is provided with resolved codes. The structured data to be serialized (defined in the proto file) need only be defined once, so that the read and write operations of the structured data can be easily completed by using different data streams by using specially generated source codes (using the generation tool provided by protobuf). The definition of the data structure in the proto file may even be updated without destroying the program compiled in dependence on the old format.
FlatBuffers is an open-source, cross-platform, efficient serialization tool library providing multiple language interfaces, implementing a serialization format similar to Protocal Buffers, mainly written by Wouter van Oortmerssen, and open-source by Google. Oortmerssen originally developed FlatBuffers for Android games and performance-oriented applications, it currently has c++, c#, C, go, java, PHP, python and JavaScript interfaces.
Taking serialization and deserialization of Java objects as examples, the mapping of JSON and Java objects is: jackson establishes a mapping relation between Java objects and JSONs by using a Java reflection mechanism and notes. By using the get and set methods of Java beans, and notes (e.g. @ JsonProperty, @ JsonIgnore, etc.), jackson can determine the correspondence between fields in Java objects and attributes in JSON.
The serialization process of the java object is as follows: when a Java object needs to be converted into a JSON (JavaScript Object Notation, a lightweight data interchange format) string, jackson traverses the fields of the Java object and then converts them into attributes and values in the corresponding JSON format.
The anti-serialization process is as follows: when the JSON string needs to be converted into a Java object, jackson parses the JSON string and maps JSON attributes to fields of the Java object. It can instantiate and set the properties of the Java object according to its constructor or setter method.
The JSON syntax specification includes:
1) Is composed of key pairs and wrapped using brackets and square brackets.
2) Key value pairs: JSON data consists of key-value pairs separated by a colon (:) between keys and values, and a (,) between each key-value pair, such as { "key": "value", "anoher_key": "anoher_value" }.
3) A key: the keys must be strings and are bracketed with double quotation marks (") that do not support single quotation marks, such as {" name ":" John "," age ": 30}.
4) Value: the value may be a string, number, boolean value, array, object, null, or other data type, such as {"name": "John", "age": 30, "isStudent": true, "grades": [90, 85, 78], "address": {"city": "New York", "zip": "10001"}, "hobbies": null}.
5) Array: expressed in brackets ([ ]) may contain a plurality of values, each separated by commas (,) such as [1, 2, 3, 4, 5].
6) The object is: indicated by brackets ({ }) and is composed of a plurality of key value pairs, each key value pair is separated by comma (,) such as { "name": "John", "age": 30, "address": { "city": "New York", "zip": "10001" }.
7) Nesting: objects or arrays can be nested within objects to represent more complex data structures, such as { s }
"name": "John",
"age": 30,
"grades": [90, 85, 78],
"address": {
"city": "New York",
"zip": "10001"
}
}。
8) Blank symbol: the blank symbols (space, line feed, tab, etc.) in JSON have no effect on parsing of the data, but can increase readability.
However, in the related art, the serialization method of the java object is complex, which results in low efficiency of the serialization process.
The embodiment of the application provides a serialization method, which comprises the steps of obtaining a data object to be serialized, determining a target character identifier corresponding to a data type to which the data object belongs, then carrying out serialization processing on the data object based on the target character identifier to obtain a serialized object, finally obtaining serialized text data corresponding to the data object according to the target character identifier and the serialized object, representing different types of data objects through a single target character identifier, and carrying out serialization processing on the data object according to different character identifiers to obtain the serialized object. And the serialization method does not need to rely on any external serialization library, so that the serialization method is lighter and is not influenced by the version or compatibility of the third party serialization library. In addition, the single character identifier and the serialized text representation are adopted, so that the readability is high.
The serialization method provided by the embodiment of the application can be applied to an application environment shown in fig. 1. Wherein device 102 communicates with device 104 over a network. The device 102 may serialize the data object to obtain serialized text data, and then transmit the serialized text data to the device 104, where the device 104 performs deserialization processing on the serialized text data to obtain the data object. The device 102 may also serialize the data objects and store the serialized text data. The terminal 102 or the device 104 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, internet of things devices and portable wearable devices, and the internet of things devices may be smart speakers, smart televisions, smart air conditioners, smart vehicle devices, and the like. The portable wearable device may be a smart watch, smart bracelet, headset, or the like. Device 102 or device 104 may also be implemented as a stand-alone server or as a cluster of servers.
In one embodiment, as shown in fig. 2, a serialization method is provided, and the method is applied to a computer device, which may be device 102 in fig. 1, for example. The serialization method includes the following steps 202 through 208.
Step 202, obtaining a data object to be serialized and a data type to which the data object belongs.
The data objects may be various types of data objects, for example, java objects.
The data types may include a base type, a reference data type, a structure data type, a custom type. The basic types may include at least one of Integer int or intel, long Integer Long or Long, short or Short, character char or character, byte or Byte, single precision floating point number Float or Float, double precision floating point number Double or Double, boolean value boost or boost; the reference data type comprises at least one of a String, sixteen-bit double-precision floating point number BigDecimal and a Date; the structure data type comprises at least one of an ordered List type List, an unordered List Set type, a mapping table Map type and a group type. Wherein BigDecimal is used to perform an accurate operation on numbers exceeding 16 significant bits. BigDecimal created are objects that require the corresponding method to be invoked. The Map type is data of a K-V (key-value) type, and K-V key value pairs are stored.
Alternatively, the device may obtain the data object to be serialized and obtain the data type to which the data object belongs.
Step 204, determining a target character identifier corresponding to the data type to which the data object belongs.
Optionally, a mapping relation between the data type and the character identifier is pre-established, and the device determines the target character identifier corresponding to the data type to which the data object belongs according to the mapping relation between the data type and the character identifier.
Wherein, the mapping relation between the data type and the character identifier can comprise: the character identifier corresponding to the int or intelger type may be a first character, such as I; the character identifier corresponding to the Long or Long type can be a second character, such as L; the Character identifier corresponding to the char or Character type may be a third Character, such as C; the Byte or the character identifier corresponding to the Byte type may be a fourth character, such as B; the character identifier of the Float or Float type may be a fifth character, such as F; the character identifier corresponding to the Double or Double type may be a sixth character, such as U; the character identifier corresponding to the Boolean or Boolean type may be a seventh character, such as J (true), and an eighth character, such as K (false); the character identifier of the Short or Short type may be a ninth character, such as O; the character identifier corresponding to the String type can be a tenth character, such as S; the character identifier corresponding to BigDecimal types may be an eleventh character, such as X; the Date type character identifier may be a twelfth character, such as D; the character identifier corresponding to the List type may be a thirteenth character, such as P; the character identifier corresponding to the Set type may be a fourteenth character, such as G; the character identifier corresponding to the Map type may be a fifteenth character, such as M; the character identifier corresponding to the array type can be a sixteenth character, such as A; the character identifier corresponding to the custom type may be a seventeenth character, such as Q.
And 206, carrying out serialization processing on the data object according to the data type of the data object to obtain a serialized object of the data object.
Optionally, configuring corresponding serialization modes based on different character identifiers in advance, and performing serialization processing on the data object by using the corresponding serialization modes based on the target character identifier by using the device to obtain a serialized object. A serialized object refers to a serialized data object.
The predefined serialization method comprises the following steps:
Basic types:
The character identifier corresponding to the int or the intelger type is I, and the value corresponding to the data object is used as a serialization object of the data object;
the character identifier corresponding to the Long or Long type is L, and the value corresponding to the data object is used as a serialization object of the data object;
The Character identifier corresponding to the char or Character type is C, and the value corresponding to the data object is used as a serialization object of the data object;
The character identifier corresponding to the Byte or the Byte type is B, and the value corresponding to the data object is used as a serialization object of the data object;
The character identifier corresponding to the Float or the Float type is F, and the value corresponding to the data object is used as a serialization object of the data object;
the character identifier corresponding to Double or Double type is U, and the value corresponding to the data object is used as the serialization object of the data object;
the character identifier corresponding to the bootan or bootan type is J (true) or K (false);
And taking the character identifier corresponding to the Short or Short type as O, and taking the value corresponding to the data object as a serialization object of the data object.
Reference data type:
the character identifier corresponding to the String type is S, the String is converted by quote, and the converted value is used as a serialization object of the data object;
the character identifier corresponding to BigDecimal types is X, and the value corresponding to the data object is taken as a serialization object of the data object;
the character identifier corresponding to the Date type is D, the Date is formatted by using the format of 'yyyy-MM-dd' T 'HH: MM: ss.SSS', and the formatted value is used as a serialization object of the data object.
Structure data type:
the character identifier corresponding to the List type is P, and the serialization is finished by P [ beginning and ending ] and recursively serializing the elements in the List;
The character identifier corresponding to the Set type is G, G [ beginning and ] ending is adopted in serialization, and elements in the Set are serialized recursively;
The character identifier corresponding to the Map type is M, and the serialization is finished by M [ beginning and ending ] and recursively serializes the mapped key value pairs;
The character identifier corresponding to the array type is A, and the array length and the element type identifier are added after the type identifier, for example, A3I represents an integer array with the length of 3. The following data type element identifiers: n: indicating a null value (null); i: represents an Integer type (intelger); l: representing a Long integer type (Long); c: representing a Character type (Character); o: representing a Short integer type (Short); b: representing Byte type (Byte); f: representing single precision floating point number type (Float); u: representing Double precision floating point number type (Double); d: indicating a Date type (Date); s: representing a String type (String); j: representing the boolean type true; k: representing boolean type false; x: a representation BigDecimal type; a: representing an array type; p: representing ArrayList type; g: a representation HashSet type; m: representing HashMap type; q: representing reading the object type according to the name; h: representing creation of array types by name.
The custom type, the corresponding character identifier is Q, and starting with Q, followed by the type name, then bracketed to represent the object properties. The object attributes may include a base data type and a structure data type. For example, the custom type is an Enum enumeration type, the character identifier is Q, followed by a type name and an enumeration constant name, such as QType { enum_value }.
Optionally, the device performs serialization processing on the data object by adopting a corresponding serialization mode according to the data type of the data object to obtain the serialized object.
And step 208, obtaining the serialized text data corresponding to the data object according to the target character identifier and the serialized object.
Optionally, the device splices the target character identifier and the serialized object to obtain serialized text data corresponding to the data object.
In this embodiment, a data object to be serialized is obtained, a target character identifier of a data type to which the data object belongs is determined, then, serialization processing is performed on the data object according to the target character identifier, a serialized object is obtained, serialized text data corresponding to the data object is obtained according to the target character identifier and the serialized object, different types of data objects are represented by a single target character identifier, then, serialization processing is performed on the data object according to different character identifiers, and a serialization object is obtained. And the method does not need to rely on any external serialization library, so that the method is lighter and is not influenced by the version or compatibility of the third party serialization library, code injection attack can be prevented, and the safety of data is improved. In addition, the single character identifier and the serialized text representation are adopted, so that the readability is high.
In an exemplary embodiment, the serialized objects include a first serialized object, a second serialized object, a third serialized object; carrying out serialization processing on the data object according to the data type of the data object to obtain a serialized object, wherein the serialization processing comprises the following steps: if the data type is a basic type or a reference data type, acquiring a value corresponding to the data object, and taking the value as a first serialization object of the data object; if the data type is a structural data type, carrying out serialization processing on each element in the data object to obtain a second serialization object of the data object; and if the data type is a custom type, acquiring a type name corresponding to the custom type, and serializing the attribute of the type name to obtain a third serialized object of the data object.
The type name corresponding to the custom type can be set according to the need, such as person, and the attribute of the type name can be set according to the need, such as name, age and the like. Each attribute may include at least one numerical value, etc.
Correspondingly, according to the target character identifier and the serialization object, obtaining the serialization text data corresponding to the data object, including: if the data type is a basic type or a reference data type, obtaining corresponding serialized text data according to the target character identifier and the first serialized object; if the data type is the structure data type, obtaining corresponding serialized text data according to the target character identifier and the second serialized object; and if the data type is a custom type, obtaining corresponding serialized text data according to the target character identifier and the third serialized object.
For the basic type, illustratively, the data type is an int type, the corresponding target character identifier is I, the value corresponding to the data object is obtained, the character identifier I and the value together form the serialized text data, for example, the data object is an integer 123, and the corresponding serialized text data is I123.
Illustratively, the data type is a long type, the corresponding target character identifier L, the value corresponding to the data object is obtained, the character identifier L and the value together form serialized text data, e.g., the data object is a long type 123456, and the corresponding serialized text data is L123456.
Illustratively, the data type is a character type, the corresponding target character identifier C, the value corresponding to the data object is obtained, the character identifier C and the value together form serialized text data, e.g., the data object is character type a, and the corresponding serialized text data is Ca.
Illustratively, the data type is a byte type, the corresponding target character identifier B, the value corresponding to the data object is obtained, the character identifier B and the value together form serialized text data, e.g., the data object is a byte type 01111111, and the corresponding serialized text data is B01111111.
Illustratively, the data type is a float type, the corresponding target character identifier F, the value corresponding to the data object is obtained, the character identifier F and the value together form serialized text data, e.g., the data object is a single precision floating point type 0.5, and the corresponding serialized text data is F0.5.
Illustratively, the data type is a double type, the corresponding target character identifier U, the value corresponding to the data object is obtained, the character identifier U and the value together form serialized text data, for example, the data object is a double precision floating point type 3.14, and the corresponding serialized text data is U3.14.
Illustratively, the data type is a boolean type, and if true corresponds to a J target character identifier, false corresponds to a K target character identifier.
Illustratively, the data type is a shot type, the corresponding target character identifier is O, the value corresponding to the data object is obtained, the character identifier O and the value together form serialized text data, for example, the data object is a short integer 32767, and the corresponding serialized text data is O32767.
In an exemplary embodiment, if the data type is a reference data type, acquiring a value corresponding to the data object, and taking the value as a first serialized object, where the method includes: when the reference data type is a character string, performing escape processing on the character string to obtain a corresponding value, and taking the value as a first serialization object; and when the reference data type is a date, formatting the date according to a specified format to obtain a corresponding value, and taking the value as a first serialization object.
Illustratively, the data type is a String type, the corresponding target character identifier S, the String is converted into a corresponding value by using a quote method, and the character identifier S and the value together form the serialized text data. For example, the character string is "Hello, world |", and the corresponding serialized text data is SHello, world |.
The data type is BigDecimal types, the corresponding target character identifier X, the value corresponding to the data object is obtained, and the character identifier X and the value together form the serialized text data. For example, bigDecimal the value of the object 123.45, the corresponding serialized text data is X123.45.
The data type is Date type, the corresponding target character identifier D, the Date is formatted by using a specified format to obtain a value, and the character identifier D and the value together form the serialized text data. For example, date data object is 2023-07-31:14:30:45.678, and the corresponding serialized text data is D2023-07-31T14:30:45.678.
The serialization of the data object is realized by adding the target character identifier and the value corresponding to the data object, the serialization mode is simple, the serialization efficiency is improved, and a third party serialization library is not needed to participate, so that the serialization method is lighter. In addition, the serialization mode supports serialization of binary data, date, time and other data types, and the processing efficiency is high.
In an exemplary embodiment, if the data type is a structural data type, performing serialization processing on each element in the data object to obtain a second serialized object of the data object; correspondingly, if the data type is a structural data type, obtaining corresponding serialized text data according to the target character identifier and the second serialized object, including: and acquiring a start identifier and an end identifier, and acquiring the serialized text data corresponding to the data object according to the target character identifier, the start identifier, the second serialized object and the end identifier.
Wherein, the start identifier may be "[", and the end identifier may be "]". And sequentially splicing the target character identifier, the start identifier, the serialized object and the end identifier to obtain serialized text data corresponding to the data object, adding the character identifier P if the data type is a List type, starting with P, adding the serialized object obtained by serializing each element, and finally adding the serialized object to indicate the end.
The target character identifier, the start identifier, the second serialization object and the end identifier are added, so that the serialization mode is simple, the serialization efficiency is improved, a third party serialization library is not needed, and the serialization method is lighter.
In an exemplary embodiment, if the data type is a structural data type, the serializing processing is performed on each element in the data object to obtain a second serialized object of the data object, including: if the data type is a structural data type, determining the data type of each element in the data object; if the data type of the element is a basic type or a reference data type, determining a target character identifier of the data type of the element and a value corresponding to the element, and obtaining a serialization element corresponding to the element according to the target character identifier of the element and the value corresponding to the element; if the data type of the element is not the basic type or the reference data type, serializing the element to obtain a serialization element corresponding to the element; and combining the serialization elements according to the arrangement sequence of each element in the data object to obtain a second serialization object of the data object.
Each element in the data object also determines a target character identifier of the data type to which the element belongs, and performs serialization processing on the element, for example, A3I indicates that the length is 3, a indicates that the data type of the data object is an array type, and I indicates that the data type of the element in the data object is an integer type.
If the data type of the element is not the basic type or the reference data type, continuing to determine the data type of each sub-element in the element, and for each sub-element, if the data type of the sub-element is the basic type or the reference data type, determining a target character identifier of the data type of the sub-element and a value corresponding to the sub-element, and according to the target character identifier of the sub-element and the value corresponding to the sub-element, obtaining a serialized sub-element corresponding to the sub-element, and if the data type of the sub-element is not the basic type or the reference data type, serializing the sub-element to obtain a serialized sub-element corresponding to the sub-element; and combining the serialized sub-elements according to the arrangement sequence of each sub-element in the element to obtain the serialized element corresponding to the element.
And carrying out serialization processing on each element in the data object in a recursion mode to obtain each serialization element, and combining the serialization elements according to the arrangement sequence of each element in the data object to obtain a serialization object corresponding to the data object, so that a data structure of cyclic reference can be supported, and correct serialization or analysis of the data can be ensured.
In an exemplary embodiment, the structure data type includes at least one of a list type, a Set type, a Map type, and a group type.
In an exemplary embodiment, the method further comprises: and when the structure data type is an array type, acquiring the array length and the element type identifier. Correspondingly, the obtaining the serialized text data corresponding to the data object according to the target character identifier, the start identifier, the second serialized object and the end identifier includes: and obtaining the serialized text data corresponding to the data object according to the target character identifier, the array length, the element type identifier, the start identifier, the second serialized object and the end identifier.
If the data object int [ ] {1,2,3}, the corresponding serialized text data is A3I [ I1I2I3], A represents the data type of the data object as the array type, 3 represents the data length, I represents the element type identifier, represents the data type of the element in the data object as integer, and the element is 1,2,3.
In an exemplary embodiment, if the data type is a custom type, a type name corresponding to the custom type is obtained, and an attribute of the type name is serialized to obtain a third serialized object of the data object.
The method further comprises the steps of: and if the structure data type is a custom type, acquiring an attribute identifier of the custom type. Correspondingly, according to the target character identifier and the third serialization object, corresponding serialization text data is obtained, including: and obtaining the serialized text data corresponding to the data object according to the target character identifier, the type name, the third serialized object and the attribute identifier.
Type names such as Color, person. The attribute identifier may be as { }. The data object Color. RED is the corresponding serialized text data QColor { RED }, Q represents the custom type, color is the type name, RED is the serialized object.
The data can be more accurately represented and analyzed by the custom type and the corresponding custom serialization mode, and specific service requirements are met.
In an exemplary embodiment, the serialization method further includes: when it is determined that the data type to which the data object belongs corresponds to a specified character identifier, the specified character identifier is used as the serialized text data, and the specified character identifier represents an empty object, for example, the specified character identifier is N. The data type to which the data object belongs is 'null', and is represented by a designated character identifier N.
In an exemplary embodiment, as shown in fig. 3, taking a data object as a Java object as an example, serializing text data as a result string is described, and a serializing method includes:
1) Starting: receiving a Java object as input, and preparing for serialization;
2) Judging whether the data type of the Java object is null:
21 If null, a character identifier N is added to the result string, representing a null object.
22 Ending the serialization.
3) Checking whether the data type of the Java object is a basic type:
31 If the data type is the int type, adding a character identifier I, and then adding a value of the Java object after the character identifier I to obtain a result character string, wherein the result character string is the serialized text data of the Java object.
32 If the data type is long type, adding a character identifier L, and then adding the value of the Java object after the character identifier L to obtain a result character string, wherein the result character string is the serialized text data of the Java object.
33 If the data type is a character type, adding a character identifier C, and then adding the value of the Java object after the character identifier C to obtain a result character string, wherein the result character string is the serialized text data of the Java object.
34 If the data type is byte type, adding a character identifier B, and then adding the value of the Java object after the character identifier B to obtain a result character string, wherein the result character string is the serialized text data of the Java object.
35 If the data type is float type, adding a character identifier F, and then adding the value of the Java object after the character identifier F to obtain a result character string, wherein the result character string is the serialized text data of the Java object.
36 If the data type is double type, adding a character identifier U, and then adding the value of the Java object after the character identifier U to obtain a result character string, wherein the result character string is the serialized text data of the Java object.
37 If the data type is a bootan type, if it is true, the character is labeled J, and false is labeled K.
38 If the data type is the shot type, adding a character identifier O, adding a value of the Java object after the character identifier O to obtain a result character string, wherein the result character string is the serialized text data of the Java object.
4) Checking whether the data type of the Java object is a reference data type:
41 If the data type is String type, adding a character identifier S, using quote method to make the character String be converted, then adding the value converted by character String after character identifier S so as to obtain the result character String, said result character String is the serialized text data of Java object.
Escape processing, for example:
PRIVATE STRING quote (String str) { - - -, escape
String builder sb= new StringBuilder () - - - - - - - -, string
for (int i = 0, n = str.length(); i < n; i++) {
char c = str.charAt(i);
switch (c) {
case '\\':
sb.append("\\\\");
break;
case '|':
sb.append("\\|");
break;
default:
sb.append(c);
break;
}
}
sb.append('|');
return sb.toString();
}
42 If the data type is BigDecimal types, adding a character identifier X, and then adding the value of the Java object after the character identifier X to obtain a result character string, wherein the result character string is the serialized text data of the Java object.
43 If the data type is Date type, adding a character identifier D, formatting the Date by using a specified format, adding a formatted value after the character identifier D, and obtaining a result character string, wherein the result character string is the serialized text data of the Java object.
5) Judging whether the data type of the Java object is the structure data type or not:
51 Judging whether the data type of the Java object is List type or not, if so, adding a character identifier P and starting with ' P ', then recursively serializing each element in the List, and ending the serialization when the last added ' is indicated.
52 Judging whether the data type of the Java object is Set type or not, if so, adding a character identifier G and starting with ' G ', then recursively serializing each element in the Set, and ending the serialization when the last addition ' indicates that the Java object is added.
53 Judging whether the data type of the Java object is Map type or not, if so, adding a character identifier M and starting with ' M ', then recursively serializing each mapped key value pair, and ending the serialization after the last addition of ' representation.
54 Judging whether the data type of the Java object is an array type or not, if so, adding a character identifier A, followed by an array length and an element type identifier, recursively serializing each element of the array, ending in the last added' representation, and ending the serialization.
55 Judging whether the data type of the Java object is a custom object, if so, using a predefined type name, adding a character identifier Q, then, bracketing the type name and a bracket to represent the attribute of the type name, then, iteratively serializing each attribute of the type name, and finally, adding the' representation to finish, and ending the serialization.
6) Ending: and recursively calling a method write, and returning a final serialization result character string.
For example, enum Color {
RED, GREEN, BLUE
}
public class Person {
public String name;
public int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public class Example {
public static void main(String[] args) {
ConvertHelper convertHelper = new ConvertHelper();
convertHelper.useClass(Color.class,"Color");
convertHelper.useClass(Person.class,"Person");
List<Object> list = new ArrayList<>();
list.add(123);
list.add("Hello, World!");
list.add(new BigDecimal("123.45"));
list.add(new Date());
list.add(Arrays.asList("apple", "banana", "orange"));
list.add(new HashSet<>(Arrays.asList(1, 2, 3)));
Map map=new HashMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
list.add(map);
list.add(new int[]{1, 2, 3});
list.add(Color.RED);
list.add(new Person("Alice", 30));
Class of implementation of/(serialization algorithm)
Writer writer = new Writer(convertHelper);
writer.write(list);
String result = writer.result();
System.out.println(result);
}
}
The output result after serialization is:
P[I123SHello,World!|X123.45D2023-07-31T23:59:00.649P[Sapple|Sbanana|Sorange|]G[I1I2I3]M[Skey1|Svalue1|Skey2|Svalue2|]A3I[I1I2I3]QColor{RED}QPerson{name=SAlice|,age=I30}].
in the serialization method in this embodiment, because a single character identifier is used to represent Java objects of different types, serialization efficiency is improved, compared with JSON serialization, no external library is needed, the serialization method is lighter and is not affected by version or compatibility of a third party serialization library, and because a data structure can be customized, a customized serialization mode allows defining required data structures and command characters (i.e., character identifiers), representation and analysis of data can be controlled more accurately, and specific service requirements are met. Because the custom serialization mode can use a more compact representation mode, smaller data volume can be generated, so that storage space and network bandwidth are saved; types such as int, byte, short, long, doublie, bigDecimal are clearly distinguished, so that precision loss is avoided; compared to FlatBuffers, protobuf, has the readability of serialized text data. In addition, the serialization method does not need to repeatedly appear like every key in JSON, so that data redundancy is not caused, the size of data can be reduced, and network overhead can be reduced for large-scale data transmission; the JSON does not support annotation, and the serialization method in the embodiment can support annotation addition to explain the meaning of the data, so that the readability of the data is improved; the serialization method in the embodiment can support the serialization of date, time, binary data and other data types; the code injection attack is prevented without relying on a third party serialization library, and the data security is improved; the serialization of binary data is supported, the serialization efficiency is improved, and the serialization of the data structure of the circular reference is supported.
As shown in fig. 4, the present embodiment further provides a reverse sequence method, which is a reverse operation process of the serialization method, and includes steps 402 to 408.
Step 402, serialized text data is acquired.
Optionally, the device obtains the serialized text data from a local store or from another device.
And step 404, analyzing the serialized text data to obtain a target character identifier.
Optionally, the device parses the serialized text data to obtain the target character identifier, e.g., parses the serialized text data A3I [ I1I2I3] to obtain the target character identifier a.
And step 406, determining the data type corresponding to the serialized text data according to the target character identifier.
Optionally, the device may determine, according to the correspondence between the character identifiers and the data types, the data type corresponding to the target character identifier, for example, the target character identifier is a, and the corresponding data type is an array type.
And step 408, performing deserialization processing on the serialized text data based on the data type to obtain a data object.
Optionally, performing deserialization processing on the serialized text data according to an deserialization mode of the data type to obtain a corresponding data object. For example I5, direct reading 5 results in data object integer data 5. For another example, A3I [ I1I2I3], reading length 3 in the serialized text data, gradually reading the elements inside to obtain corresponding integer elements {1,2,3}, and obtaining the corresponding data object as an array int [ ] {1,2,3}.
According to the anti-serialization method provided by the embodiment of the application, the serialized text data is acquired, analyzed to obtain the target character identifier, and then the data object is subjected to anti-serialization processing based on the target character identifier to obtain the data object, so that the efficiency of the serialization process is improved due to relatively simple serialization rules, and the corresponding anti-serialization process is relatively simple, so that the efficiency of the anti-serialization process is improved. And does not need to rely on any external libraries so that it is lighter and not affected by the version or compatibility of the third party serialization library.
In an exemplary embodiment, the performing, based on the data type, deserializing the serialized text data to obtain a corresponding data object includes: if the data type is a basic type or a reference data type, reading a value from the serialized text data, and determining the value as a data object; if the data type is a structural data type, reading an element in the serialized text data, and obtaining a data object according to the element; if the data type is a custom type, analyzing the type name in the serialized text data to obtain a data object, wherein the data object comprises the attribute of the type name and the data corresponding to each attribute.
The basic types may include at least one of Integer int or intel, long Integer Long or Long, short or Short, character char or character, byte or Byte, single precision floating point number Float or Float, double precision floating point number Double or Double, boolean value boost or boost; the reference data type includes at least one of a string String, bigDecimal and a Date.
For example, the basic type is the int type, the serialized text data is I12, and the corresponding value 12 is directly read, and 12 is taken as the data object.
The structure data type includes at least one of a List type List, a Set type, a Map type, and a group type.
For example, the data type is a custom type Q, the serialized text data is QColor { RED }, the type name in the serialized text data is analyzed to obtain a Color, and a data object is obtained, where the data object includes data RED corresponding to the attribute of the type name, and the data object is Color.
If the data type is the custom type Q, the serialized text data is QPerson { name= SAlice |, and age=i30 }, analyzing the type name in the serialized text data to obtain Person, and then analyzing the attributes name and age of the type name step by step to obtain the data object Person ("Alice", 30).
In an exemplary embodiment, if the data type is a structural data type, reading an element in the serialized text data, and obtaining a data object according to the element, where the method includes: if the structure data type is an array type, reading an array length and an element type identifier in the serialized text data; determining the number of the elements according to the array length; determining the data type of the element according to the element type identifier; and reading the elements in the serialized text data according to the number of the elements and the data types of the elements, and obtaining the data objects according to the elements.
For example, the data type is an array, the serialized text data is A3I [ I1I2I3], the length of the read array is 3, 3 elements can be determined according to the length of the array 3, the data type of the 3 elements can be determined to be integer according to the element type identifier I, and then the elements in the serialized text data are read according to the number of the elements and the data type of the elements, so that the data object int [ ] {1,2,3} is obtained.
In one exemplary embodiment, as shown in FIG. 5, a method of reverse serialization comprises:
1) Beginning to receive a serialization text data, analyzing to obtain command characters, namely target character identifiers:
11 Reading command characters of the data type, and executing corresponding logic according to different command characters to analyze the data of the corresponding type.
2) Command characters are basic data types and reference data types:
21 If the command character is 'N', indicating a null value, return directly to null.
22 If the command character is 'I', 'L', 'C', 'O', 'B', 'F', 'U', 'D', 'X', representing an integer, a long integer, a character, a short integer, a byte, a floating point number, a double precision floating point number, a date, bigDecimal type data, respectively, reads the corresponding numerical character string and converts it into the corresponding Java type.
23 If the command character is 'J', indicating the boolean type true, directly returning true.
24 If the command character is 'K', indicating boolean type false, return false directly.
25 If the command character is 'S', representing a string, reading and parsing the string with the escape character.
3) Command characters are structured data types:
31 If the command character is 'A', representing array type data, reading array length and element type identifier in the serialized text data, determining the number of elements according to the array length, determining the data type of the elements according to the element type identifier, reading elements in the serialized text data according to the number of the elements and the data type of the elements, and obtaining Java objects according to the elements.
32 If the command character is 'P', representing List type data, reading elements in the serialized text data to obtain a Java object.
33 If the command character is 'G', representing the Set type data, reading the elements in the serialized text data to obtain the Java object.
34 If the command character is 'M', representing Map type data, reading key value pairs in the serialized text data, and obtaining Java objects.
35 If the command character is 'Q', representing the custom type, reading the data corresponding to the attribute of the type name according to the type name, and obtaining the Java object.
4) The end returns an inverse serialized data object.
It should be understood that, although the steps in the flowcharts related to the embodiments described above are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Based on the same inventive concept, the embodiment of the application also provides a training device for the table analysis model for realizing the training method of the table analysis model, and a table analysis device for realizing the table analysis method. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation in the embodiments of the training device and the table parsing device for one or more table parsing models provided below may be referred to the above limitation on the training method and the table parsing method for the table parsing model, and the specific limitation is not repeated herein.
In one embodiment, as shown in fig. 6, a serialization apparatus is provided that includes a first acquisition module 602, a first determination module 604, a serialization module 606, and a processing module 608. Wherein:
the first obtaining module 602 is configured to obtain a data object to be serialized and a data type to which the data object belongs.
The first determining module 604 is configured to determine a target character identifier corresponding to a data type to which the data object belongs.
The serialization module 606 is configured to perform serialization processing on the data object according to the data type to which the data object belongs, so as to obtain a serialized object of the data object.
The processing module 608 is configured to obtain serialized text data corresponding to the data object according to the target character identifier and the serialized object.
In an exemplary embodiment, the serialized objects include a first serialized object, a second serialized object, a third serialized object; the serialization module 606 is further configured to obtain a value corresponding to the data object if the data type is a basic type or a reference data type, and take the value as a first serialized object of the data object; if the data type is a structural data type, carrying out serialization processing on each element in the data object to obtain a second serialization object of the data object; and if the data type is a custom type, acquiring a type name corresponding to the custom type, and serializing the attribute of the type name to obtain a third serialized object of the data object.
In one exemplary embodiment, the base type includes at least one of integer, long integer, short integer, character, byte, single precision floating point number, double precision floating point number, and boolean value; the reference data type includes at least one of a string, sixteen-bit double-precision floating point number BigDecimal, and a date.
In an exemplary embodiment, the serialization module 606 is further configured to, if the reference data type is a string, perform an escape process on the string to obtain a corresponding value, and take the value as the first serialization object; and if the reference data type is a date, formatting the date according to a specified format to obtain a corresponding value, and taking the value as the first serialization object.
In an exemplary embodiment, the serialization module 606 is further configured to determine a data type to which each element in the data object belongs if the data type is a structure data type; if the data type of the element is a basic type or a reference data type, determining a target character identifier of the data type of the element and a value corresponding to the element, and obtaining a serialization element corresponding to the element according to the target character identifier of the element and the value corresponding to the element; if the data type of the element is not the basic type or the reference data type, serializing the element to obtain a serialization element corresponding to the element; and combining the serialization elements according to the arrangement sequence of each element in the data object to obtain a second serialization object of the data object.
In an exemplary embodiment, the structure data type includes at least one of a list type, a Set type, a Map type, and a group type.
In an exemplary embodiment, the processing module 608 is further configured to obtain a start identifier and an end identifier, and obtain the serialized text data of the data object according to the target character identifier, the start identifier, the second serialized object and the end identifier.
In an exemplary embodiment, the processing module 608 is further configured to obtain an array length of the data object and an element type identifier of the data object if the structure data type is an array type; and obtaining the serialized text data corresponding to the data object according to the target character identifier, the array length, the element type identifier, the start identifier, the second serialized object and the end identifier.
In an exemplary embodiment, the processing module 608 is further configured to obtain an attribute identifier of the custom type if the structural data type is the custom type; and obtaining the serialized text data corresponding to the data object according to the target character identifier, the array length, the element type identifier, the start identifier, the second serialized object and the end identifier.
As shown in fig. 7, the present application provides a reverse-sequence apparatus, which includes a second acquisition module 702, a parsing module 704, a second determining module 706, and a reverse-serialization module 708. Wherein:
The second acquisition module 702 is configured to acquire serialized text data.
The parsing module 704 is configured to parse the serialized text data to obtain a target character identifier.
The second determining module 706 is configured to determine a data type corresponding to the serialized text data according to the target character identifier.
The deserializing module 708 is configured to deserialize the serialized text data based on the data type, to obtain a data object.
In an exemplary embodiment, the anti-serialization module 708 is further configured to read a value from the serialized text data if the data type is a base type or a reference data type, and determine the value as a data object; if the data type is a structural data type, reading an element in the serialized text data, and obtaining a data object according to the element; if the data type is a custom type, analyzing the type name in the serialized text data to obtain a data object, wherein the data object comprises the attribute of the type name and the data corresponding to each attribute.
In an exemplary embodiment, the anti-serialization module 708 is further configured to, if the structure data type is an array type, read an array length and an element type identifier in the serialized text data, determine the number of elements according to the array length, determine the data type of the elements according to the element type identifier, and read the elements in the serialized text data according to the number of elements and the data type of the elements to obtain a data object.
The various modules in the serialization apparatus or the deserialization apparatus described above may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, which may be a terminal or a server, and the internal structure of which may be as shown in fig. 8. The computer device includes a processor, a memory, an input/output interface, and a communication interface. The computer device may further comprise a display unit and an input means. The processor, the memory and the input/output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input/output interface. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The input/output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless mode can be realized through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. The computer program, when executed by a processor, implements a training method or a form parsing method for a form parsing model. The display unit of the computer device is used for forming a visual picture, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, can also be a key, a track ball or a touch pad arranged on the shell of the computer equipment, and can also be an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the structure shown in FIG. 8 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In one embodiment, a computer device is provided that includes a memory having a computer program stored therein and a processor that implements the steps of the serialization method or the deserialization method when the computer program is executed by the processor.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when executed by a processor, implements the steps of a serialization method or an anti-serialization method.
In one embodiment, a computer program product is provided comprising a computer program which, when executed by a processor, implements the steps of a serialization method or a deserialization method.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (ReRAM), magneto-resistive random access Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (PHASE CHANGE Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in various forms such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The databases referred to in the embodiments provided herein may include at least one of a relational database and a non-relational database. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processor referred to in the embodiments provided in the present application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, or the like, but is not limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The foregoing examples illustrate only a few embodiments of the application and are described in detail herein without thereby limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of the application should be assessed as that of the appended claims.

Claims (15)

1. A method of serializing comprising:
Acquiring a data object to be serialized and a data type to which the data object belongs;
Determining a target character identifier corresponding to the data type of the data object;
carrying out serialization processing on the data object according to the data type of the data object to obtain a serialized object of the data object;
And obtaining the serialized text data corresponding to the data object according to the target character identifier and the serialized object.
2. The method according to claim 1, wherein the serialized objects include a first serialized object, a second serialized object, and a third serialized object, and the performing the serialization processing on the data object according to the data type to which the data object belongs to, to obtain the serialized object of the data object includes:
If the data type is a basic type or a reference data type, acquiring a value corresponding to the data object, and taking the value as a first serialization object of the data object;
if the data type is a structural data type, carrying out serialization processing on each element in the data object to obtain a second serialization object of the data object;
And if the data type is a custom type, acquiring a type name corresponding to the custom type, and serializing the attribute of the type name to obtain a third serialized object of the data object.
3. The method according to claim 2, wherein if the data type is a reference data type, obtaining a value corresponding to the data object, and taking the value as the first serialized object includes:
If the reference data type is a character string, performing escape processing on the character string to obtain a corresponding value, and taking the value as the first serialization object;
And if the reference data type is a date, formatting the date according to a specified format to obtain a corresponding value, and taking the value as the first serialization object.
4. The method according to claim 2, wherein if the data type is a structure data type, performing serialization processing on each element in the data object to obtain a second serialized object of the data object, including:
If the data type is a structural data type, determining the data type of each element in the data object;
If the data type of the element is a basic type or a reference data type, determining a target character identifier of the data type of the element and a value corresponding to the element, and obtaining a serialization element corresponding to the element according to the target character identifier of the element and the value corresponding to the element;
If the data type of the element is not the basic type or the reference data type, serializing the element to obtain a serialization element corresponding to the element;
and combining the serialization elements according to the arrangement sequence of each element in the data object to obtain a second serialization object of the data object.
5. The method according to claim 2, wherein the obtaining, from the target character identifier and the serialized object, serialized text data corresponding to the data object includes:
And acquiring a start identifier and an end identifier, and obtaining the serialized text data of the data object according to the target character identifier, the start identifier, the second serialized object and the end identifier.
6. The method of claim 5, wherein the method further comprises:
if the structure data type is an array type, acquiring the array length of the data object and an element type identifier of the data object;
the obtaining the serialized text data corresponding to the data object according to the target character identifier, the start identifier, the second serialized object and the end identifier includes:
And obtaining the serialized text data corresponding to the data object according to the target character identifier, the array length, the element type identifier, the start identifier, the second serialized object and the end identifier.
7. The method according to claim 2, wherein the method further comprises:
if the structure data type is a custom type, acquiring an attribute identifier of the custom type;
And obtaining the serialized text data corresponding to the data object according to the target character identifier and the serialized object, wherein the serialized text data comprises the following components:
And obtaining the serialized text data corresponding to the data object according to the target character identifier, the type name, the third serialized object and the attribute identifier.
8. A method of reverse serialization, comprising:
Acquiring serialized text data;
Analyzing the serialized text data to obtain a target character identifier;
Determining a data type corresponding to the serialized text data according to the target character identifier;
and performing deserialization processing on the serialized text data based on the data type to obtain a data object.
9. The method of claim 8, wherein the performing deserialization processing on the serialized text data based on the data type to obtain a corresponding data object comprises:
If the data type is a basic type or a reference data type, reading a value from the serialized text data, and determining the value as a data object;
if the data type is a structural data type, reading an element in the serialized text data, and obtaining a data object according to the element;
If the data type is a custom type, analyzing the type name in the serialized text data to obtain a data object, wherein the data object comprises the attribute of the type name and the data corresponding to each attribute.
10. The method according to claim 9, wherein if the data type is a structure data type, reading an element in the serialized text data, and obtaining a data object according to the element, includes:
If the structure data type is an array type, reading an array length and an element type identifier in the serialized text data;
Determining the number of the elements according to the array length;
determining the data type of the element according to the element type identifier;
Reading elements in the serialized text data according to the number of the elements and the data types of the elements;
and obtaining the data object according to the element.
11. A serialization apparatus, comprising:
the first acquisition module is used for acquiring a data object to be serialized and a data type to which the data object belongs;
The first determining module is used for determining a target character identifier corresponding to the data type of the data object;
The serialization module is used for carrying out serialization processing on the data object according to the data type of the data object to obtain a serialized object of the data object;
And the processing module is used for obtaining the serialized text data corresponding to the data object according to the target character identifier and the serialized object.
12. A reverse serialization apparatus, comprising:
The second acquisition module is used for acquiring the serialized text data;
the analysis module is used for analyzing the serialized text data to obtain a target character identifier;
The second determining module is used for determining the data type corresponding to the serialized text data according to the target character identifier;
And the deserializing module is used for deserializing the serialized text data based on the data type to obtain a data object.
13. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 7, or of claims 8 to 10, when the computer program is executed.
14. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 7, or of claims 8 to 10.
15. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 7, or of claims 8 to 10.
CN202311451105.4A 2023-11-02 2023-11-02 Serialization method and device, deserialization method and device, and computer equipment Pending CN117973322A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311451105.4A CN117973322A (en) 2023-11-02 2023-11-02 Serialization method and device, deserialization method and device, and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311451105.4A CN117973322A (en) 2023-11-02 2023-11-02 Serialization method and device, deserialization method and device, and computer equipment

Publications (1)

Publication Number Publication Date
CN117973322A true CN117973322A (en) 2024-05-03

Family

ID=90852084

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311451105.4A Pending CN117973322A (en) 2023-11-02 2023-11-02 Serialization method and device, deserialization method and device, and computer equipment

Country Status (1)

Country Link
CN (1) CN117973322A (en)

Similar Documents

Publication Publication Date Title
US9892144B2 (en) Methods for in-place access of serialized data
CN105760534B (en) Data structure, hadoop cluster, server and its application method of customized serializability
US9483240B1 (en) Data binding dependency analysis
CN106648569B (en) Target serialization realization method and device
CN111680061A (en) Data access method, device, equipment and storage medium
JP7350923B2 (en) Deep learning framework operator registration method, equipment, device and storage medium
WO2021217846A1 (en) Interface data processing method and apparatus, and computer device and storage medium
TWI713015B (en) Language recognition method and device
CN112930529A (en) Generating software artifacts from conceptual data models
US11720534B2 (en) Remote code execution
WO2022042252A1 (en) Driver configuration management method and apparatus, medium, device, and system
CN111159215A (en) Mapping method and device of Java class and relational database and computing equipment
US20130218933A1 (en) Consistent selective sub-hierarchical serialization and node mapping
CN114327435A (en) Technical document generation method and device and computer readable storage medium
CN113138755A (en) JSON serialization and deserialization optimization method and system
CN115629763A (en) Target code generation method and NPU instruction display method and device
CN117973322A (en) Serialization method and device, deserialization method and device, and computer equipment
CN116414689A (en) Interface parameter verification method and system based on reflection mechanism
CN114222317B (en) Data processing method and device, electronic equipment and storage medium
CN113254455B (en) Dynamic configuration method and device of database, computer equipment and storage medium
CN115145559A (en) Configuration management method, device and equipment based on Flutter
CN114816408A (en) Information processing method and device
CN117149153A (en) Method, device, computer equipment and medium for generating business data model
CN114722112A (en) Visual list data display method and device
CN113778846A (en) Method and apparatus for generating test data

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