Data deserialization method, device, apparatus, and storage medium

By using data filling and transformation rules during data deserialization, the problem of missing fields or type mismatches in the data model is solved, resulting in more stable data processing.

CN114741065BActive Publication Date: 2025-12-19SHENZHEN SHANJIAN INTELLIGENT SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210389589.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-13
Publication Date
2025-12-19
Estimated Expiration
2042-04-13

AI Technical Summary

Technical Problem

In existing technologies, the process of deserializing data into a data model is prone to interruption or crash, mainly due to missing data in field definitions or type mismatch.

Method used

By establishing a data model, traversing field definitions, and searching for corresponding object data, if any data is missing, default values ​​are generated using preset data filling rules. If the data types do not match, data conversion is performed to ensure the integrity of the data model.

Benefits of technology

This reduces the probability of data deserialization process crashes and improves the security and reliability of data processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114741065B_ABST
    Figure CN114741065B_ABST
Patent Text Reader

Abstract

The application provides a data deserialization method, device, equipment and storage medium, wherein the method comprises the following steps: establishing a data model; receiving request data to be deserialized; traversing each field definition in the data model; whenever a field definition is traversed, checking whether object data corresponding to the field definition exists in the request data; for any field definition, if the object data corresponding to the field definition does not exist in the request data, obtaining a default value of the field definition based on a preset data filling rule table, and taking the default value as the object data of the field definition to construct an entity object of the field definition. In the process of deserializing the request data into the data model, when missing data is encountered, a default value is automatically generated to replace the missing data for filling, thereby reducing the probability of a crash in the deserialization process and making the process safer and more reliable.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data processing, and in particular to a data deserialization method, device, equipment and storage medium. BACKGROUND

[0002] The first step of the application development process is to design and define a database. After the database is designed and defined, the background needs to define a data model for each data entity and establish an interface between the data model and the data access layer, and then map the data of the data model to the database or file. In the application development process, the data interaction between the front end and the background, when the front end sends a request data to the background, the background deserializes the request data sent by the front end into a data model, and then realizes the data interaction with the database through the interface between the data model and the data access layer. At present, in the process of deserializing data into a data model in the background, there are often problems of missing data or mismatched data types in some field definitions. At this time, the process of deserializing data into a data model is prone to interruption or crash.

[0003] Therefore, the prior art still needs to be improved and developed. SUMMARY

[0004] The main purpose of the present application is to solve the technical problem that the existing method of deserializing data into a data model is prone to crash.

[0005] The first aspect of the present application provides a data deserialization method, which comprises:

[0006] establishing a data model;

[0007] receiving request data to be deserialized;

[0008] traversing each field definition in the data model;

[0009] Whenever a field definition is traversed, it is checked whether there is object data corresponding to the field definition in the request data;

[0010] For any field definition, if the object data corresponding to the field definition does not exist in the request data, the default value of the field definition is obtained based on a preset data filling rule table, and the entity object of the field definition is constructed by taking the default value as the object data of the field definition.

[0011] In an optional embodiment of the first aspect of the present application, the data deserialization method further comprises:

[0012] For any one of the field definitions, if the object data corresponding to the field definition exists in the request data, it is further judged whether the data type of the object data is consistent with the field type of the field definition;

[0013] If the data type of the object data is consistent with the field type of the field definition, the entity object of the field definition is directly constructed by using the object data;

[0014] If the data type of the object data is inconsistent with the field type of the field definition, the object data is converted based on a preset data conversion rule table to obtain conversion data, and the entity object of the field definition is constructed by using the conversion data.

[0015] In an optional implementation of the first aspect of the present application, the traversing each field definition in the data model comprises:

[0016] Each field definition in the data model is traversed, and the field name and the field type of each field definition are obtained by introspection.

[0017] In an optional implementation of the first aspect of the present application, the finding, whenever a field definition is traversed, whether the object data corresponding to the field definition exists in the request data comprises:

[0018] The request data is parsed based on the syntax rule of the request data, and all field names included in the request data and the object data corresponding to each field name are extracted;

[0019] Whenever a field definition is traversed, it is judged whether the object data corresponding to the field definition exists in the request data based on field name matching.

[0020] In an optional implementation of the first aspect of the present application, for any one of the field definitions, if the object data corresponding to the field definition does not exist in the request data, the default value of the field definition is obtained based on a preset data filling rule table, and the entity object of the field definition is constructed by using the default value as the object data of the field definition.

[0021] For any one of the field definitions, if the object data corresponding to the field definition does not exist in the request data, the field type of the field definition is obtained, the default value corresponding to the field definition is obtained from the data filling rule table based on the field type, and the entity object of the field definition is constructed by using the default value as the object data of the field definition.

[0022] In an optional implementation of the first aspect of the present application, if the data type of the object data is inconsistent with the field type of the field definition, the object data is converted based on a preset data conversion rule table to obtain conversion data, and the entity object of the field definition is constructed using the conversion data, including:

[0023] obtaining a conversion rule of the object data from the data conversion rule table based on the data type of the object data and the field type of the field definition;

[0024] converting the object data based on the conversion rule to obtain conversion data of the object data, and constructing the entity object of the field definition using the conversion data.

[0025] In an optional implementation of the first aspect of the present application, the content of the data filling rule table includes a field type, a default value and a description, and the content of the data filling rule table includes a data type, a field type and a conversion rule.

[0026] The second aspect of the present application provides a data deserialization device, including:

[0027] a establishing module for establishing a data model;

[0028] a receiving module for receiving request data to be deserialized;

[0029] a traversing module for traversing each field definition in the data model;

[0030] a searching module for searching for whether there is object data corresponding to the field definition in the request data whenever a field definition is traversed;

[0031] a first constructing module for, for any field definition, if the object data corresponding to the field definition does not exist in the request data, obtaining a default value of the field definition based on a preset data filling rule table, and constructing an entity object of the field definition using the default value as the object data of the field definition.

[0032] The third aspect of the present application provides a data deserialization device, including a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected through a circuit;

[0033] The at least one processor calls the instructions in the memory to make the data table conversion device execute the data deserialization method of any one of the above.

[0034] The fourth aspect of the present application provides a computer readable storage medium, and the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method for data deserialization according to any one of the preceding aspects.

[0035] Beneficial effects: the present application provides a method, device, equipment and storage medium for data deserialization, wherein the method comprises establishing a data model; receiving request data to be deserialized; traversing each field definition in the data model; whenever a field definition is traversed, checking whether object data corresponding to the field definition exists in the request data; for any field definition, if the object data corresponding to the field definition does not exist in the request data, obtaining a default value of the field definition based on a preset data filling rule table, and constructing an entity object of the field definition by taking the default value as the object data of the field definition. In the process of deserializing the request data into the data model, when missing data is encountered, a default value is automatically generated to replace the missing data for filling, thereby reducing the probability of crash in the deserialization process, and making the process more secure and reliable. BRIEF DESCRIPTION OF DRAWINGS

[0036] Figure 1 An embodiment diagram of the method for data deserialization of the present application;

[0037] Figure 2 An embodiment diagram of the device for data deserialization of the present application;

[0038] Figure 3 An embodiment diagram of the equipment for data deserialization of the present application. DETAILED DESCRIPTION

[0039] The embodiments of the present application provide a method, device, equipment and storage medium for data deserialization. The terms "first", "second", "third", "fourth" and the like (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the term "comprise" or "have" and any variation thereof is intended to cover non-exclusive inclusion, for example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to the process, method, product or device.

[0040] Reference Figure 1The first aspect of the present application provides a data deserialization method, which comprises:

[0041] S100, establishing a data model; in this step, a data model is established by a business, and a data structure of the data model used in the present application is exemplarily illustrated in a StudentModel structure, which includes field definition information such as uid: Int, name: String, birth: Date and scores: float;

[0042] S200, receiving request data to be deserialized; in this step, the source of the request data can be a network, Bluetooth or broadcast; the request data is data written in a certain syntax structure, and the content included in the request data can be quickly obtained by parsing the data according to a data protocol (for example, JSON, XML) agreed with a data producer, the request data includes a plurality of field names and object data corresponding to each field name, and each field name and the object data corresponding thereto are arranged next to each other;

[0043] S300, traversing each field definition in the data model; in this embodiment, each field definition is traversed in the order of the field definition in the data model; the traversing each field definition in the data model includes traversing each field definition in the data model and obtaining the field name and the field type of each field definition by introspection. Taking the above StudentModel model as an example, the traversal order is to traverse uid: Int first, then find whether there is a field name of uid in the request data, and if so, obtain the object data recorded after the field name; if not, find the default value (for example, 0) corresponding to Int in the data filling rule table, and take the default value as the object data of uid, then write uid: "0" in the entity object corresponding to the data model, and then traverse the next name; if the type of the object data of name recorded in the request data is Int, the object data is formatted to obtain the converted data as the object data corresponding to name in the entity object; then the next birth is traversed;

[0044] S400, whenever a field definition is traversed, whether the object data corresponding to the field definition exists in the request data is found; in step S400, since the request data can be written based on different syntax rules (for example, JSON, XML), the whenever a field definition is traversed, whether the object data corresponding to the field definition exists in the request data is found specifically includes:

[0045] parsing the request data based on a syntax rule of the request data, and extracting all field names included in the request data and object data corresponding to each of the field names; in this step, the purpose of parsing is to extract useful field names and object data from the request data, and to remove standard text belonging to the syntax;

[0046] Whenever a field definition is traversed, it is determined whether the object data corresponding to the field definition exists in the request data based on a field name matching manner. In this step, taking the StudentModel model as an example, when age is traversed, it is determined whether the field name age exists in the field names obtained after parsing, and if the field name age exists, the object data “18” corresponding to age is further obtained.

[0047] S500, for any one of the field definitions, if the object data corresponding to the field definition does not exist in the request data, a default value of the field definition is obtained based on a preset data filling rule table, and an entity object of the field definition is constructed by taking the default value as the object data of the field definition. The content of the data filling rule table includes three items of field type, default value and description. An exemplary data filling rule table of the present application is as follows:

[0048] Field Type Default Value Description Int 0 Float 0.0 Boolean false String "" Empty string Array [] Array object with 0 elements Dictionary {:} Dictionary object with 0 elements

[0049] In step S500, for any one of the field definitions, if the object data corresponding to the field definition does not exist in the request data, a default value of the field definition is obtained based on a preset data filling rule table, and an entity object of the field definition is constructed by taking the default value as the object data of the field definition. The content of the data filling rule table includes three items of field type, default value and description. An exemplary data filling rule table of the present application is as follows:

[0050] For any one of the field definitions, if the object data corresponding to the field definition does not exist in the request data, the field type of the field definition is obtained, the default value corresponding to the field definition is obtained from the data filling rule table based on the field type, and an entity object of the field definition is constructed by taking the default value as the object data of the field definition. For example, taking the scores field name in the StudentModel model as an example, if the scores field name cannot be found in the request data, “0.0” is taken as the object data of scores.

[0051] Referring to Figure 1 In an optional embodiment of the first aspect of the present application, the data deserialization method further comprises:

[0052] S600, for any one of the field definitions, if the request data exists in the object data corresponding to the field definition, further determine whether the data type of the object data is consistent with the field type of the field definition; in the process of serializing data, although the request data includes the object data of this field definition in the data model, the object data may be filled incorrectly and is not the real data corresponding to this field definition, since the type is not consistent, there may be an error in the serialization process, so it is also necessary to determine whether the data type of the object data in the request data is consistent with the field type of the field definition;

[0053] S700, if the data type of the object data is consistent with the field type of the field definition, directly construct the entity object of the field definition with the object data; for example, taking the birth field name in the above StudentModel model as an example, if the birth field name is found in the request data, and the object data corresponding to birth is Date, then the entity object of birth in the data model is directly constructed with the object data;

[0054] S800, if the data type of the object data is inconsistent with the field type of the field definition, the object data is converted based on a preset data conversion rule table to obtain conversion data, and the entity object of the field definition is constructed with the conversion data. For example, taking the birth field name in the above StudentModel model as an example, if the birth field name is found in the request data, but the object data corresponding to birth is not Date, then the object data of birth needs to be further converted according to the data filling rule table.

[0055] For example, a data filling rule table of the application is as follows, the content of the data filling rule table includes data type, field type and conversion rule three contents:

[0056]

[0057]

[0058] In step S800, if the data type of the object data is inconsistent with the field type of the field definition, the object data is converted based on a preset data conversion rule table to obtain conversion data, and the entity object of the field definition is constructed with the conversion data. For example, taking the birth field name in the above StudentModel model as an example, if the birth field name is found in the request data, but the object data corresponding to birth is not Date, then the object data of birth needs to be further converted according to the data filling rule table.

[0059] The conversion rule of the object data is obtained from the data conversion rule table based on the data type of the object data and the field type of the field definition; taking the StudentModel model as an example, the field type corresponding to the uid in the data model is Int, if the object data corresponding to the uid in the request data is “abcd”, “abcd” is obviously not of the Int type, so the conversion of “abcd” is required;

[0060] The object data is converted based on the conversion rule, the conversion data of the object data is obtained, and the entity object of the field definition is constructed by using the conversion data. Referring to the above table, the field type is Int, and the data type is String, so the string “abcd” needs to be converted into a numerical type.

[0061] In summary, the steps of the data deserialization method of the application can be simplified as follows: 1, a data model is established through a business; 2, data of any source (such as a network, Bluetooth or broadcast) is received; 3, the data is parsed through a data protocol (such as JSON or XML) agreed with a data producer; 4, all fields (including field names and field types) of the model are obtained through introspection of the model; 5, the data parsed in step 3 is matched with the field names and field types in step 4, and the data is saved into the model when the matching is successful; 6, when the data is missing or does not match, a data filling method is used to make the parsing still continue (reference 3); 7, the final model is output. When the data is missing, the data filling rule is triggered, and when the data does not match, the data is first converted according to the data conversion rule, and when the conversion fails, the data filling rule is triggered.

[0062] Referring to Figure 2 , the second aspect of the application provides a data deserialization device, the data deserialization device comprises:

[0063] The establishing module 10 is configured to establish a data model;

[0064] The receiving module 20 is configured to receive request data to be deserialized;

[0065] The traversal module 30 is configured to traverse each field definition in the data model;

[0066] The searching module 40 is configured to search, whenever a field definition is traversed, whether there is object data corresponding to the field definition in the request data;

[0067] The first constructing module 50 is configured to, for any one of the field definitions, if the object data corresponding to the field definition does not exist in the request data, obtain a default value of the field definition based on a preset data filling rule table, and construct an entity object of the field definition by taking the default value as the object data of the field definition.

[0068] In an optional implementation of the second aspect of the present application, the data deserialization device further comprises:

[0069] The judging module is configured to, for any one of the field definitions, if the object data corresponding to the field definition exists in the request data, further judge whether the data type of the object data is consistent with the field type of the field definition;

[0070] The second constructing module is configured to, if the data type of the object data is consistent with the field type of the field definition, directly construct an entity object of the field definition by taking the object data.

[0071] The third constructing module is configured to, if the data type of the object data is not consistent with the field type of the field definition, convert the object data based on a preset data conversion rule table to obtain conversion data, and construct an entity object of the field definition by taking the conversion data.

[0072] In an optional implementation of the second aspect of the present application, the traversing module comprises:

[0073] The traversing unit is configured to traverse each field definition in the data model, and obtain the field name and the field type of each field definition by introspection.

[0074] In an optional implementation of the second aspect of the present application, the searching module comprises:

[0075] The parsing unit is configured to parse the request data based on the syntax rule of the request data, and extract all field names included in the request data and object data corresponding to each field name.

[0076] The searching unit is configured to, whenever a field definition is traversed, judge whether the object data corresponding to the field definition exists in the request data based on field name matching.

[0077] In an optional implementation of the second aspect of the present application, the first constructing module comprises:

[0078] The first constructing unit is configured to, for any one of the field definitions, obtain the field type of the field definition, and obtain the default value of the field definition from the data filling rule table based on the field type.

[0079] In an optional implementation of the second aspect of the present application, the third construction module comprises:

[0080] a third construction unit, configured to obtain a conversion rule of the object data from the data conversion rule table based on a data type of the object data and a field type of the field definition, and convert the object data based on the conversion rule to obtain converted data of the object data.

[0081] In an optional implementation of the second aspect of the present application, the content of the data filling rule table comprises a field type, a default value and a description, and the content of the data filling rule table comprises a data type, a field type and a conversion rule.

[0082] Figure 3 is a structural schematic diagram of a data deserialization device provided by an embodiment of the present application. The data deserialization device can be different in configuration or performance and can include one or more processors 60 (central processing units, CPU) (for example, one or more processors) and a memory 70, one or more storage media 80 (for example, one or more mass storage devices) for storing application programs or data. The memory and the storage media can be temporary storage or persistent storage. The programs stored in the storage media can include one or more modules (not shown in the figure), and each module can include a series of instruction operations in the data deserialization device. Further, the processor can be configured to communicate with the storage media and execute the series of instruction operations in the storage media on the data deserialization device.

[0083] The data deserialization device of the present application can further include one or more power supplies 90, one or more wired or wireless network interfaces 100, one or more input / output interfaces 110, and / or one or more operating systems, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art can understand that Figure 3 The structure of the data deserialization device shown does not constitute a specific limitation on the data deserialization device of the present application and can include more or fewer components than shown, or combine certain components, or different component arrangements.

[0084] The application further provides a computer readable storage medium, which can be a nonvolatile computer readable storage medium or a volatile computer readable storage medium, and the computer readable storage medium stores instructions, and the instructions make a computer execute the steps of the data deserialization method when the instructions are run on the computer.

[0085] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described system or device, unit can refer to the corresponding processes in the foregoing method embodiments, and will not be described here.

[0086] The integrated unit, if realized in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the application essentially or the part of the prior art that makes a contribution or the whole or part of the technical solutions can be embodied in the form of a software product, the computer software product is stored in a storage medium, and includes a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in each embodiment of the 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 various program code storage media.

[0087] The above-described embodiments are only used to illustrate the technical solutions of the application, rather than limit the application; although the application is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the application.

Claims

1. A method of data de-serialization, the method comprising: The method for data deserialization comprises: establishing a data model; receiving request data to be deserialized; traversing each field definition in the data model; for each field definition, searching for object data corresponding to the field definition in the request data; for any field definition, if the object data corresponding to the field definition does not exist in the request data, obtaining a default value of the field definition based on a preset data filling rule table, the content of the data filling rule table including field type, default value and description, and constructing an entity object of the field definition with the default value as the object data of the field definition; the method for data deserialization further comprises: for any field definition, if the object data corresponding to the field definition exists in the request data, further judging whether the data type of the object data is consistent with the field type of the field definition; if the data type of the object data is consistent with the field type of the field definition, directly constructing an entity object of the field definition with the object data; if the data type of the object data is inconsistent with the field type of the field definition, converting the object data based on a preset data conversion rule table to obtain conversion data, and constructing an entity object of the field definition with the conversion data, the content of the data conversion rule table including data type, field type and conversion rule; the traversing each field definition in the data model comprises: traversing each field definition in the data model, and obtaining the field name and field type of each field definition through introspection; the searching for object data corresponding to the field definition in the request data comprises: parsing the request data based on the syntax rule of the request data, and extracting all field names included in the request data and object data corresponding to each field name; for each field definition, judging whether the object data corresponding to the field definition exists in the request data based on field name matching.

2. The method of data de-serialization of claim 1, wherein, the obtaining a default value of the field definition based on a preset data filling rule table, the content of the data filling rule table including field type, default value and description, and constructing an entity object of the field definition with the default value as the object data of the field definition comprises: for any field definition, if the object data corresponding to the field definition does not exist in the request data, obtaining the field type of the field definition, obtaining the default value corresponding to the field definition from the data filling rule table based on the field type, and constructing an entity object of the field definition with the default value as the object data of the field definition.

3. The method of data de-serialization of claim 1, wherein, If the data type of the object data is inconsistent with the field type of the field definition, the object data is converted based on a preset data conversion rule table to obtain conversion data, and the entity object of the field definition is constructed by using the conversion data. The conversion rule of the object data is obtained from the data conversion rule table based on the data type of the object data and the field type of the field definition. The object data is converted based on the conversion rule to obtain conversion data of the object data, and the entity object of the field definition is constructed by using the conversion data.

4. An apparatus for data de-serialization, the apparatus comprising: The data deserialization device comprises: A data model is established. A request data to be deserialized is received. Each field definition in the data model is traversed. For each field definition, it is determined whether the object data corresponding to the field definition exists in the request data. For any one of the field definitions, if the object data corresponding to the field definition does not exist in the request data, a default value of the field definition is obtained based on a preset data filling rule table, and the entity object of the field definition is constructed by using the default value as the object data of the field definition, and the content of the data filling rule table comprises field type, default value and description. The data deserialization device further comprises: For any one of the field definitions, if the object data corresponding to the field definition exists in the request data, it is further determined whether the data type of the object data is consistent with the field type of the field definition. For any one of the field definitions, if the object data corresponding to the field definition exists in the request data, it is further determined whether the data type of the object data is consistent with the field type of the field definition. For any one of the field definitions, if the object data corresponding to the field definition does not exist in the request data, a default value of the field definition is obtained based on a preset data filling rule table, and the entity object of the field definition is constructed by using the default value as the object data of the field definition, and the content of the data filling rule table comprises field type, default value and description. The traversal module comprises: A traversal unit is configured to traverse each field definition in the data model and obtain the field name and field type of each field definition by introspection. The finding module comprises: An analysis unit is configured to analyze the request data based on the syntax rule of the request data, and extract all field names included in the request data and the object data corresponding to each field name. A finding unit is configured to determine whether the object data corresponding to the field definition exists in the request data based on field name matching when traversing each field definition.

5. An apparatus for data de-serialization, the apparatus comprising: The data deserialization device comprises a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected by a circuit. The at least one processor invokes the instructions in the memory to cause a conversion device of the data table to perform the method of data de-serialization of any of claims 1-3.

6. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program, which when executed by a processor implements the method of data de-serialization of any of claims 1-3.

Citation Information

Patent Citations

  • Database query completion method and device and computer equipment

    CN111008191A

  • Data processing method, device and equipment and computer storage medium

    CN111737404A