Data interaction method and device and nonvolatile storage medium
By combining serialization and deserialization with abstract classes and annotations, the problems of precision loss and low conversion efficiency caused by inconsistent data types between the front-end and back-end are solved, the data type is unified and efficiently converted, and the maintainability and performance of the system are improved.
Patent Information
- Application Number
- CN202510711695.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-29
- Publication Date
- 2025-09-19
AI Technical Summary
The data interaction between the front-end and back-end suffers from loss of precision and unsatisfactory conversion efficiency due to inconsistent data types. The existing technology increases code complexity and reduces system maintainability and scalability through hard coding.
Serialization and deserialization are used to convert front-end data into structured data. Data type conversion is performed through abstract classes and annotations to eliminate dependence on hard coding and ensure the accuracy and efficient transmission of data between the front and back ends.
It achieves the unification and standardization of front-end and back-end data types, improves data conversion efficiency, avoids overflow errors, and enhances the maintainability and scalability of the system.
Smart Images

Figure CN120669984A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information technology, and in particular to a data interaction method, device, and non-volatile storage medium. Background Art
[0002] In web development projects, the differences between the front-end and back-end technology stacks lead to significant disparities in their ability to handle numerical precision. Specifically, the Java technology stack used on the back-end supports a wider range of numbers, while the JavaScript (JS) on the front-end experiences precision loss when processing values above a certain threshold, leading to data inaccuracy and potentially threatening the correct execution of system functions. To circumvent this precision issue, converting all numerical data to string types for transmission and storage ensures numerical integrity and accuracy on the front-end, but inevitably negatively impacts database performance. This is because string values are less efficient than numeric values in storing and retrieving data in a database.
[0003] In related technologies, two different sets of parameter types are often redundantly defined on the backend, and numerical type conversion is performed through hard coding. This not only increases the complexity of the code, but also reduces the maintainability and scalability of the system, and there is a problem of unsatisfactory data conversion efficiency between the frontend and the backend.
[0004] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention
[0005] The embodiments of the present application provide a data interaction method, device, and non-volatile storage medium to at least solve the technical problem of unsatisfactory front-end and back-end data conversion efficiency in related technologies.
[0006] According to one aspect of an embodiment of the present application, a data interaction method is provided, including: obtaining front-end data of an initial data structure, wherein the initial data structure uses a serialized manner for data representation; performing deserialization processing based on the front-end data to obtain first data of a target data structure, wherein the target data structure uses a structured manner for data representation, and the deserialization processing is used to convert the data representation from a structured manner to a serial manner; performing data type conversion on the first data to obtain second data; and performing business processing according to the second data to obtain a processing result.
[0007] Optionally, before performing deserialization processing based on the front-end data to obtain the first data, the method also includes: determining, based on the front-end data, an interface code that the front-end data needs to request; sending the front-end data to an implementation class corresponding to the interface code according to the interface code, wherein the implementation class is used to execute predetermined business logic; based on the abstract class corresponding to the implementation class, determining a processing method for performing deserialization processing on the front-end data, wherein the abstract class is used to constrain the implementation class.
[0008] Optionally, converting the first data to obtain second data includes: annotating the target data type on the first data using a predetermined annotation method; and performing data conversion processing on the first data using a predetermined class according to the annotated target data type to obtain the second data of the target data type.
[0009] Optionally, according to the annotated target data type, a predetermined class is used to perform conversion processing on the first data to obtain the second data of the target data type, including: using the predetermined class to rewrite a predetermined processing method to obtain a rewritten processing method, wherein the processing method is determined based on an abstract class, and the implementation class corresponding to the abstract class corresponds to the interface code of the front-end data request; using the rewritten processing method to perform data type conversion processing on the first data according to the annotated target data type to obtain the second data of the target data type.
[0010] Optionally, the initial data type of the first data is a string type, and the target data type is a numeric type.
[0011] Optionally, after performing business processing according to the second data and obtaining the processing result, the method further includes: serializing the processing result of the target data structure to obtain the serialized processing result; performing data type conversion on the serialized processing result to obtain feedback data; and sending the feedback data to the front-end server.
[0012] Optionally, before obtaining the front-end data of the initial data structure, the front-end server performs the following processing: processing the initial data of the front-end server to obtain the front-end data of the initial data structure; using the front-end data of the initial data structure to submit an interaction request to the back-end server.
[0013] Optionally, the initial data structure is a JSON string, and the target data structure is a Java object.
[0014] According to another aspect of an embodiment of the present application, a data interaction device is provided, including: a data acquisition module, used to acquire front-end data of an initial data structure, wherein the initial data structure uses a serialized method for data representation; a deserialization module, used to perform deserialization processing based on the front-end data to obtain first data of a target data structure, wherein the target data structure uses a structured method for data representation, and the deserialization processing is used to convert the data representation from a structured method to a serial method; a data type conversion, used to perform data type conversion on the first data to obtain second data; and a business processing module, used to perform business processing according to the second data to obtain a processing result.
[0015] According to another aspect of an embodiment of the present application, a non-volatile storage medium is provided, wherein the non-volatile storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing any one of the data interaction methods described above.
[0016] According to another aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement any one of the data interaction methods described.
[0017] In an embodiment of the present application, by obtaining front-end data of an initial data structure, wherein the initial data structure uses a serialized data representation; performing deserialization processing based on the front-end data to obtain first data of a target data structure, wherein the target data structure uses a structured data representation, and the deserialization processing is used to convert the data representation from a structured representation to a serial representation; performing data type conversion on the first data to obtain second data; and performing business processing according to the second data to obtain a processing result. The purpose of eliminating the reliance on hard coding for front-end and back-end data conversion is achieved, and the technical effect of avoiding overflow errors during data interaction and improving data conversion efficiency is achieved, thereby solving the technical problem of unsatisfactory front-end and back-end data conversion efficiency in related technologies. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0019] Figure 1 is a flowchart of an optional data interaction method provided according to an embodiment of the present application;
[0020] Figure 2is a schematic diagram of an optional data interaction method provided according to an embodiment of the present application;
[0021] Figure 3 This is a schematic diagram of an optional data interaction device provided according to an embodiment of the present application. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0023] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0024] For ease of description, some nouns or terms involved in the embodiments of the present application are explained below:
[0025] JSON is a lightweight data exchange format based on a subset of ECMAScript (the JS specification developed by the European Computer Manufacturers Association). It uses a text format that is completely independent of programming languages to store and represent data. Its simplicity and clear hierarchical structure make JSON an ideal data exchange language. It is easy for humans to read and write, as well as for machines to parse and generate, and significantly improves network transmission efficiency.
[0026] The primary function of an abstract class (AbstractEntranceHandler) is to provide a general framework and behavioral specifications to guide and constrain the behavior of specific implementation classes. It typically contains method declarations (with or without method bodies) and some common implementation details. Abstract classes are often used to represent abstract concepts derived from problem domain analysis and design. They represent an abstraction of a series of seemingly different, but essentially the same, concrete concepts.
[0027] The specific role of the implementation class is to provide specific method implementations for specific business scenarios or data types based on the abstract class.
[0028] Hard-coding generally refers to programming with fixed values or specific logic, rather than through parameters, configuration files, or dynamic calculations. When dealing with front-end and back-end data type conversions, hard-coding often involves writing type conversion logic directly into the code, manually writing conversion code for each data field that needs to be converted.
[0029] According to an embodiment of the present application, a method embodiment of data interaction is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0030] Figure 1 This is a flow chart of a data interaction method according to an embodiment of the present application, wherein the optional execution subject is a backend server, such as Figure 1 As shown, the method includes the following steps:
[0031] Step S102, obtaining front-end data of the initial data structure, wherein the initial data structure is represented by serialization;
[0032] It can be understood that the front-end data of the initial data structure (JSON string) transmitted by the front-end server is collected. The above front-end data is the serialized result after front-end processing, that is, the data structure is converted into a transmittable text format, ensuring that the data can be transmitted on the network in a lightweight and easy-to-parse form.
[0033] In an optional embodiment, before obtaining the front-end data of the initial data structure, the front-end server performs the following processing: processing the initial data of the front-end server to obtain the front-end data of the initial data structure; using the front-end data of the initial data structure, submitting an interaction request to the back-end server.
[0034] It can be understood that the information in the front-end data is analyzed to identify the specific interface code (i.e., interface code) targeted by this data request. This process is accomplished by parsing specific fields in the JSON data packet, ensuring that the data can be accurately routed to the corresponding back-end processing logic. According to the parsed interface code, the front-end data is forwarded to the matching implementation class. The implementation class is a specific business logic processing unit responsible for executing functions related to the interface code, such as database queries, data format conversion, business rule checks, etc. By determining the abstract class corresponding to the implementation class, the specific deserialization processing method is clarified. The abstract class here acts as a template in the design pattern, defining the general framework and rules for deserialization processing, constraining and guiding the implementation of its implementation class. This approach not only enhances the readability and maintainability of the code, but also ensures the consistency and standardization of data processing.
[0035] By identifying and parsing the interface code in the front-end data, accurate routing of data requests is achieved, ensuring that the data can be correctly sent to the implementation class responsible for executing specific business logic, thereby improving the system's response speed and accuracy.
[0036] In an optional embodiment, the initial data structure is a JSON string, and the target data structure is a Java object.
[0037] As you can see, converting JSON strings to Java objects unifies and standardizes front-end and back-end data formats, ensuring compatibility and consistency during data transmission and processing. Using Java objects directly leverages Java language features, such as its rich data types and robust library support, improving data processing efficiency and performance. Java objects provide more direct and efficient support for operations such as database interaction and algorithmic calculations.
[0038] It should be noted that JSON strings and Java objects are two different data representations in serialization. JSON strings (JavaScript Object Notation) are a lightweight data exchange format that usually exists in string form and is suitable for network transmission. Key-value pairs are used to represent data, and arrays and objects are used to organize data structures. Java objects are object-oriented programming concepts based on the Java language. They are instances defined by classes and have properties and methods. Java objects exist in the form of object graphs in memory and can be operated directly in the Java environment. JSON strings and Java objects differ in data representation, processing methods, performance characteristics, and language and platform compatibility. In front-end and back-end data interaction, JSON strings are used as the transmission format, while Java objects are used when the back-end server performs business logic processing.
[0039] Optionally, the frontend data is submitted as a JSON string to a unified backend interface method. For example, a backend service interface might be named ExcellentProductService.commonCustomer. "ExcellentProductService.commonCustomer" is a reference to a specific method in the backend service. By calling this method, the frontend sends a JSON-formatted request to the backend, requesting that the backend execute the common customer business logic associated with premium products. The frontend data can include the complete form data as a JSON string, along with the requested interface code.
[0040] Step S104: performing deserialization processing based on the front-end data to obtain first data of the target data structure, wherein the target data structure uses a structured manner for data representation, and the deserialization processing is used to convert the data representation from the structured manner to a serial manner;
[0041] As can be understood, after receiving the front-end data, the back-end system uses deserialization technology to parse the front-end data, such as a JSON string, back into its original data structure, generating the first data. The deserialization process essentially converts the serialized text data into structured data, such as Java objects, that the system can understand and manipulate. This process enables the back-end to interpret the data transmitted from the front-end.
[0042] It should be noted that deserialization is the reverse process of serialization, which converts serialized data back into the original object or data structure. In web development, received JSON strings are converted back into Java objects so that they can be used in the back-end code. The main function of deserialization is to reconstruct data objects, converting serialized data obtained from the network or storage back into objects in the program, restoring their original state. The JSON string submitted by the front-end is converted into Java objects that can be processed by the back-end, so that the data can be used in the business logic. The serialized data is parsed into a data structure that can perform specific operations, such as converting an array in JSON into a Java List or array.
[0043] In the above embodiment, the JSON string submitted by the front-end server needs to be converted into a Java object through deserialization so that the back-end code can correctly parse and process the data. This is achieved by calling a function of the deserialization framework, such as the JSON.parseObject() method, which converts the JSON string into a Java object.
[0044] In an optional embodiment, before performing deserialization processing based on the front-end data to obtain the first data, the method also includes: determining the interface code that the front-end data needs to request based on the front-end data; sending the front-end data to the implementation class corresponding to the interface code according to the interface code, wherein the implementation class is used to execute predetermined business logic; based on the abstract class corresponding to the implementation class, determining the processing method for performing deserialization processing on the front-end data, wherein the abstract class is used to constrain the implementation class.
[0045] It can be understood that the information in the front-end data is parsed to determine the interface code that the front-end data targets. This is done by identifying and extracting key fields in the JSON string, ensuring the precise direction of the data request. Once the interface code is determined, the front-end data will be sent to the corresponding implementation class according to the code. The implementation class is the module in the back-end system responsible for executing specific business logic, processing functions related to the interface code, such as data query, format conversion, rule checking, etc. This data distribution mechanism based on interface code improves the system's response speed and processing accuracy. Based on the implementation class of the received data, the abstract class associated with it is searched to determine the specific method for performing deserialization processing. The abstract class provides a set of data processing standards that can be followed for the implementation class, ensuring that the deserialization operation of the implementation class complies with the overall design specifications of the system.
[0046] By introducing interface code recognition, precise data distribution, and abstract class constraint mechanisms, the accuracy and efficiency issues in front-end and back-end data processing are effectively solved. At the same time, the overall performance of the system and the maintainability of the code are improved, providing a more efficient and elegant data processing process for Web development.
[0047] Optionally, the unified backend interface requests different implementation classes based on the passed interface name. For example, the commonCustomer method will complete the distribution action based on the different interface codes in the parameters. The classes that specifically complete the business are integrated into the abstract class AbstractEntranceHandler. This abstract class defines the interface or method specifications that the implementation class must comply with, such as the deserialization method deserialize and the general logic for data type conversion. By inheriting the abstract class AbstractEntranceHandler, the implementation class can not only inherit the basic functions it provides, but also must implement the abstract methods it defines, thereby ensuring that all implementation classes follow unified rules and processes in data processing and conversion.
[0048] Step S106, performing data type conversion on the first data to obtain second data;
[0049] It can be understood that the first data obtained by deserialization is converted into a type, and the string type value transmitted by the front end is converted into the corresponding Java numeric type (such as Long, Double, etc.) to generate the second data. This ensures that when the back end processes the data, it can fully utilize Java's high-precision support for numeric values and avoid data precision loss.
[0050] It should be noted that data types are categories used to define data in computer programming languages. They describe the properties of data, including how the data is stored, possible operations, and the specific values that can be stored.
[0051] Numeric types are a type of data type that is specifically used to represent numerical data. They can be divided into integer types and floating-point types: Integer types include short integers (short), int, and long integers (long). They are used to store values without decimals. The range of integer types depends on the specific implementation. For example, the int type in Java can store values from -2 to 1000. 31 to 2 31- 1. Floating-point types: include single-precision floating-point type (float) and double-precision floating-point type (double). Used to store values containing decimals, floating-point types use scientific notation to store values and can handle very large or very small values.
[0052] String types represent a collection of characters and are commonly used to store textual data such as names, addresses, and descriptions. Strings can contain letters, numbers, spaces, and special characters. The implementation of string types may vary across programming languages, with some languages treating strings as primitive types and others as object types.
[0053] In an optional embodiment, converting the first data to obtain the second data includes: annotating the target data type on the first data using a predetermined annotation method; and performing data conversion processing on the first data according to the annotated target data type using a predetermined class to obtain second data of the target data type.
[0054] It can be understood that the first data (i.e., Java object) obtained by deserializing the JSON string is type-converted to meet the needs of business logic processing, using a predetermined annotation method to mark the data type that needs to be converted, and using a specific class to perform the conversion operation. A predetermined annotation (such as a custom @AutomaticLongCodec) is used on the field or method of the Java object to indicate the target data type, for example, converting from a string type to a long integer (Long) or other numeric type. The use of annotations is highly flexible and can accurately locate which data needs to be converted and into what type, reducing the need for hard coding and making the logic of data type conversion more intuitive and easy to manage.
[0055] Based on the target data type specified in the annotation, the system uses a predefined class (for example, the AutomaticLongCodec class, which implements the custom ObjectSerializer and ObjectDeserializer interfaces) to perform the data conversion process. This class contains specialized methods, such as deserialize and write, for converting the annotated data from its current type to the target type. Through this process, the specified fields in the first data are converted to a numeric type suitable for backend processing, forming the second data.
[0056] By using annotations to mark the data types that require conversion, conversion logic is separated from business logic, improving code clarity and maintainability. Developers can intuitively see which data requires special processing during transmission, eliminating the need to intersperse type conversion logic within business processing code. This also enables the program to automatically identify and execute type conversion operations, reducing errors and complexity in manual coding.
[0057] In an optional embodiment, according to the annotated target data type, a predetermined class is used to perform conversion processing on the first data to obtain second data of the target data type, including: using the predetermined class to rewrite the predetermined processing method to obtain the rewritten processing method, wherein the processing method is determined based on the abstract class, and the implementation class corresponding to the abstract class corresponds to the interface code of the front-end data request; using the rewritten processing method to perform data type conversion processing on the first data according to the annotated target data type to obtain second data of the target data type.
[0058] It can be understood that according to the target data type indicated by the annotation, a predefined class is used to perform type conversion on the first data (i.e., the original front-end data received) to obtain the second data (converted data) adapted for back-end processing. A predetermined class (e.g., the AutomaticLongCodec class) is used, which inherits from an abstract class. This abstract class (e.g., AbstractEntranceHandler) defines the basic framework and interface for processing front-end data, including abstract methods for data type conversion. By overriding specific methods defined in the abstract class (e.g., methods in the ObjectSerializer and ObjectDeserializer interfaces), the implementation class can customize the logic of data conversion to meet specific data type requirements. According to the annotation information in the front-end data, the above-mentioned overridden processing method is called to perform the conversion from the first data to the second data. The annotation contains information about the target data type, such as converting a string type value passed by the front-end into a numeric type (e.g., Long) required for back-end processing. By calling the overridden method, data conversion can be accurately performed according to the target data type indicated by the annotation.
[0059] By encapsulating data conversion logic within abstract classes and their implementation classes, the system code becomes more modular, easier to understand, and easier to maintain. Rewriting specific processing methods rather than directly modifying the business logic code ensures the independence of data conversion, avoids code clutter and redundancy, and reduces maintenance costs. The separation of data conversion processing from business logic reduces code coupling between different modules, making each part more independent and facilitating independent testing and optimization.
[0060] In an optional embodiment, the initial data type of the first data is a string type, and the target data type is a numeric type.
[0061] It is understandable that the type conversion process of the first data received from the front end, where the initial data type of the first data is a string type, needs to be converted to a numeric type according to the requirements of the back-end processing. Such data type conversion usually occurs when processing data submitted by the front end in Web development, because the front end (such as JavaScript) may encounter precision issues when processing large numbers, while the back end (such as Java) can provide more accurate numerical processing capabilities. After converting the string type value to a numeric type, the precision loss problem that occurs when the front-end JavaScript processes large numbers can be avoided, ensuring the accuracy of the data during transmission and processing.
[0062] Step S108: Perform business processing according to the second data to obtain a processing result.
[0063] It can be understood that business logic processing is performed based on the converted second data, and finally a processing result is generated. At this stage, the data has been transformed into a form suitable for back-end operations, and business processing such as database operations and algorithm calculations can be performed efficiently and accurately.
[0064] In an optional embodiment, after performing business processing according to the second data and obtaining the processing results, the method also includes: serializing the processing results of the target data structure to obtain serialized processing results; performing data type conversion on the serialized processing results to obtain feedback data; and sending the feedback data to the front-end server.
[0065] It is understandable that after the business processing is completed, the back-end system will convert the processing results into the initial data structure, such as a string in JSON format. This process is called serialization. You can use a serialization library or tool to convert the Java object (that is, the target data structure) into a JSON string (initial data structure) for easy transmission over the network. The converted serialized processing results form feedback data, and the back-end system sends this feedback data back to the front-end server. After receiving the feedback data, the front-end can directly parse it into a JSON object for further logical processing or rendering display.
[0066] By converting numeric results to strings before sending them to the frontend, we effectively avoid the potential loss of precision when processing large numbers, ensuring the accuracy of displayed data. String data is easier to process on the frontend and is not subject to numeric type restrictions. This improves the compatibility of data exchange between the frontend and backend, allowing the frontend to seamlessly parse and display complex data structures returned by the backend.
[0067] It should be noted that serialization refers to the process of converting objects in a program into a serialized format that can be stored or transmitted. In web development, it involves converting Java objects (or objects in other programming languages) into a format that can be easily transmitted over the network, such as a JSON string. The main purpose of serialization is to store data: convert the state of an object into a byte stream or some text format so that it can be saved to a file, database, or other persistent storage. Convert an object into a byte stream or text (such as JSON) so that it can be sent to a remote server or client over the network. Simplify processing: convert complex data structures into a simple, linear data format for easy parsing and manipulation.
[0068] In the above optional embodiment, the serialization operation occurs when data is returned from the front end to the back end. After the business processing is completed, the Java object needs to be serialized into a JSON string so that the front end can receive and parse it. This is usually achieved by calling a function of the serialization framework, such as the JSON.toJSONString() method, which converts the Java object into a JSON string.
[0069] Through the above step S102, the front-end data of the initial data structure is obtained, wherein the initial data structure uses a serialized data representation; step S104, deserialization processing is performed based on the front-end data to obtain the first data of the target data structure, wherein the target data structure uses a structured data representation, and the deserialization processing is used to convert the data representation from a structured data representation to a serial data representation; step S106, data type conversion is performed on the first data to obtain second data; step S108, business processing is performed according to the second data to obtain a processing result. This can achieve the purpose of eliminating the reliance on hard coding for front-end and back-end data conversion, achieve the technical effect of avoiding overflow errors during data interaction, and improve data conversion efficiency, thereby solving the technical problem of unsatisfactory front-end and back-end data conversion efficiency in related technologies.
[0070] Based on the above embodiments and optional embodiments, this application proposes an optional implementation method: Figure 2 is a schematic diagram of an optional data interaction method provided according to an embodiment of the present application, such as Figure 2 As shown, the following is explained.
[0071] Step S1: The front-end data is submitted in the form of a JSON string to the back-end unified interface method ExcellentProductService.commonCustomer. This data includes the complete form data in the form of a JSON string and the interface code to be requested.
[0072] In step S2, the unified backend interface requests different implementation classes based on the passed interface name. The commonCustomer method in step S1 completes the distribution action based on the different interface codes in the parameters. The classes that specifically complete the business are integrated into the abstract class AbstractEntranceHandler, ensuring the uniformity and scalability of the processing logic.
[0073] In step S3, the abstract class executes the deserialize method to deserialize the JSON string into an object. The deserialize method is defined in the abstract class and performs data deserialization. If you have data that requires special processing, you can implement this method to perform special deserialization processing. Otherwise, deserialization is performed in the default manner.
[0074] In step S4, define a custom annotation and class AutomaticLongCodec to implement the ObjectSerializer interface and override methods in ObjectDeserializer to complete data type conversion. This class extends the parameters of the @JSONField annotation defined in the framework. Override the deserialize and getFastMatchToken methods in ObjectSerializer to convert string types to corresponding numeric types and return them for subsequent processing.
[0075] Step S5: The completion of the operation in step S4 is the completion of the deserialization operation, and the deserialized data is returned through the deserialize method in step S3.
[0076] Step S6: Get the data processed in step S5 to complete subsequent business operations.
[0077] Step S7: After the business operation is completed, the return value is serialized via JSON.toJSONString and returned to the front-end server. At this time, the write method in the ObjectDeserializer interface overridden in the custom class in step S4 is executed to convert the numeric type parameter into a string type and then return it to the front-end server.
[0078] Step S8: The data is returned successfully and the entire business process is completed.
[0079] like Figure 2 The key steps outlined by the dotted lines effectively avoid the drawbacks of hard coding by adopting the strategies of abstract classes, annotations, and serialization / deserialization interfaces.
[0080] The abstract class AbstractEntranceHandler defines the deserialize method, providing a unified framework and standard for all implementation classes that inherit from it. By encapsulating common deserialization logic in the abstract class, you avoid having to rewrite deserialization code in each specific implementation class, reducing code redundancy and hardcoding.
[0081] Custom annotations are used as metadata, marking Java object properties to indicate that these properties require special handling during serialization and deserialization, namely type conversion. Instead of inserting type conversion logic directly into business code, annotations are used to indirectly specify it, achieving code decoupling and enhancing code readability and maintainability.
[0082] The ObjectSerializer and ObjectDeserializer interfaces allow developers to customize data serialization and deserialization behavior. By implementing these interfaces and overriding the necessary methods, you can convert specific data types at the ingress and egress of data transmission without explicitly implementing the conversion logic in your business logic code. This approach is a targeted solution to the problem of hard-coding, centralizing conversion logic, reducing errors, and increasing code flexibility.
[0083] Through this mechanism, this optional implementation separates the data type conversion logic from the specific business processing code, making the business logic clearer and free from the interference of data processing details. When business requirements or data types change, only the abstract class, annotations, or serialization / deserialization interface implementations need to be modified, without modifying the business code, significantly reducing the rigidity and modification costs associated with hard-coding.
[0084] Through programming principles such as abstraction, encapsulation, decoupling and reuse, the drawbacks of hard coding in related technologies are effectively avoided.
[0085] This optional implementation achieves at least the following: It unifies conversions by defining abstract methods in a single abstract class, and uses annotations to elegantly convert data types, achieving a balance between business and performance. It also enables conversions between different data types on the frontend and backend, avoiding code bloat caused by hard-coded conversions defined for different data types within the same system. It also prevents data errors caused by loss of precision of numeric types when used on the frontend.
[0086] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0087] In this embodiment, a data interaction device is also provided, which is used to implement the above-mentioned embodiments and preferred embodiments. The details that have been described will not be repeated here. As used below, the terms "module" and "device" can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0088] According to an embodiment of the present application, there is also provided an embodiment of a device for implementing a data interaction method. Figure 3 is a schematic diagram of a data interaction device according to an embodiment of the present application, such as Figure 3As shown, the above-mentioned data interaction device includes: a data acquisition module 302, a deserialization module 304, a data type conversion 306, and a business processing module 308. The device is described below.
[0089] The data acquisition module 302 is used to acquire the front-end data of the initial data structure, wherein the initial data structure is represented by serialization;
[0090] A deserialization module 304 is connected to the data acquisition module 302 and is used to perform a deserialization process based on the front-end data to obtain first data of a target data structure, wherein the target data structure uses a structured method for data representation, and the deserialization process is used to convert the data representation from the structured method to a serial method;
[0091] Data type conversion 306, connected to the deserialization module 304, for performing data type conversion on the first data to obtain second data;
[0092] The business processing module 308 is connected to the data type conversion module 306 and is used to perform business processing according to the second data to obtain a processing result.
[0093] In a data interaction device provided by an embodiment of the present application, a data acquisition module 302 is set to obtain the front-end data of the initial data structure, wherein the initial data structure uses a serialized data representation; a deserialization module 304 is connected to the data acquisition module 302 and is used to perform deserialization processing based on the front-end data to obtain the first data of the target data structure, wherein the target data structure uses a structured data representation, and the deserialization processing is used to convert the data representation from a structured method to a serial method; a data type conversion 306 is connected to the deserialization module 304 and is used to perform data type conversion on the first data to obtain the second data; a business processing module 308 is connected to the data type conversion 306 and is used to perform business processing according to the second data to obtain a processing result. The purpose of eliminating the reliance on hard coding for front-end and back-end data conversion is achieved, and the technical effect of avoiding overflow errors in the data interaction process and improving data conversion efficiency is achieved, thereby solving the technical problem of unsatisfactory front-end and back-end data conversion efficiency in related technologies.
[0094] It should be noted that the above modules can be implemented by software or hardware. For example, for the latter, it can be implemented in the following ways: the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0095] It should be noted that the data acquisition module 302, deserialization module 304, data type conversion 306, and business processing module 308 correspond to steps S102 to S108 in the embodiment. The examples and application scenarios implemented by these modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiment. It should be noted that the above modules, as part of the device, can be run on a computer terminal.
[0096] It should be noted that the optional or preferred implementation of this embodiment can be found in the relevant description in the embodiment, which will not be repeated here.
[0097] The above-mentioned data interaction device can also include a processor and a memory. The data acquisition module 302, the deserialization module 304, the data type conversion 306, the business processing module 308, etc. are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize the corresponding functions.
[0098] The processor includes a kernel, which retrieves the corresponding program unit from memory. There can be one or more kernels. Memory may include non-permanent memory in a computer-readable medium, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory includes at least one memory chip.
[0099] An embodiment of the present application provides a non-volatile storage medium on which a program is stored, and when the program is executed by a processor, a data interaction method is implemented.
[0100] An embodiment of the present application provides an electronic device, comprising a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented: obtaining front-end data of an initial data structure, wherein the initial data structure uses a serialized data representation; performing deserialization processing based on the front-end data to obtain first data of a target data structure, wherein the target data structure uses a structured data representation, and the deserialization processing is used to convert the data representation from a structured data representation to a serial data representation; performing data type conversion on the first data to obtain second data; and performing business processing according to the second data to obtain a processing result. The device herein may be a server, a PC, or the like.
[0101] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having the following method steps: obtaining front-end data of an initial data structure, wherein the initial data structure uses a serialized manner for data representation; performing deserialization processing based on the front-end data to obtain first data of a target data structure, wherein the target data structure uses a structured manner for data representation, and the deserialization processing is used to convert the data representation from a structured manner to a serial manner; performing data type conversion on the first data to obtain second data; performing business processing according to the second data to obtain a processing result.
[0102] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0103] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0104] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0105] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0106] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0107] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0108] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0109] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0110] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0111] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A data interaction method, characterized in that: include: Acquire front-end data of an initial data structure, wherein the initial data structure uses a serialized manner for data representation; Performing deserialization processing based on the front-end data to obtain first data of a target data structure, wherein the target data structure uses a structured manner for data representation, and the deserialization processing is used to convert the data representation from the structured manner to a serial manner; performing data type conversion on the first data to obtain second data; Business processing is performed according to the second data to obtain a processing result.
2. The method according to claim 1, characterized in that Before performing deserialization processing based on the front-end data to obtain the first data, the method further includes: Based on the front-end data, determining the interface code that the front-end data needs to request; According to the interface code, the front-end data is sent to the implementation class corresponding to the interface code, wherein the implementation class is used to execute predetermined business logic; Based on the abstract class corresponding to the implementation class, a processing method for performing deserialization processing on the front-end data is determined, wherein the abstract class is used to constrain the implementation class.
3. The method according to claim 1, characterized in that The converting the first data to obtain second data includes: Annotating the target data type in the first data using a predetermined annotation method; According to the annotated target data type, a predetermined class is used to perform data conversion processing on the first data to obtain the second data of the target data type.
4. The method according to claim 3, characterized in that The converting process of the first data using a predetermined class according to the annotated target data type to obtain the second data of the target data type includes: Rewriting a predetermined processing method using the predetermined class to obtain a rewritten processing method, wherein the processing method is determined based on an abstract class, and an implementation class corresponding to the abstract class corresponds to the interface code of the front-end data request; The rewritten processing method is used to perform data type conversion processing on the first data according to the annotated target data type to obtain the second data of the target data type.
5. The method according to claim 3, characterized in that The initial data type of the first data is a string type, and the target data type is a number type.
6. The method according to claim 1, characterized in that After performing business processing according to the second data and obtaining a processing result, the method further includes: performing serialization processing on the processing result of the target data structure to obtain a serialized processing result; Performing data type conversion on the serialized processing result to obtain feedback data; The feedback data is sent to the front-end server.
7. The method according to claim 1, characterized in that Before obtaining the front-end data of the initial data structure, the front-end server performs the following processing: Processing the initial data of the front-end server to obtain the front-end data of the initial data structure; The front-end data of the initial data structure is used to submit an interaction request to a back-end server.
8. The method according to any one of claims 1 to 7, characterized in that The initial data structure is a JSON string, and the target data structure is a Java object.
9. A data interaction device, characterized in that: include: A data acquisition module is used to acquire front-end data of an initial data structure, wherein the initial data structure is represented by data in a serialized manner; a deserialization module, configured to perform a deserialization process based on the front-end data to obtain first data of a target data structure, wherein the target data structure uses a structured manner for data representation, and the deserialization process is configured to convert the data representation from the structured manner to a serial manner; Data type conversion, used to perform data type conversion on the first data to obtain second data; The business processing module is used to perform business processing according to the second data to obtain a processing result.
10. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the data interaction method according to any one of claims 1 to 8.