Data format conversion method and device, server, medium and computer program

By automating the processing of JSON data to generate interface documentation, the problem of low efficiency and high error rate in generating class files by developers manually writing JSON parameters has been solved, achieving more efficient class file generation.

CN118194826BActive Publication Date: 2026-01-13CHERY AUTOMOBILE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410465438.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-17
Publication Date
2026-01-13
Estimated Expiration
2044-04-17

Smart Images

  • Figure CN118194826B_ABST
    Figure CN118194826B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of data processing, in particular to a data format conversion method and device, a server, a medium and a computer program, wherein the method comprises the following steps: creating a string object; storing attribute values of format data to be converted into the string object, and identifying data types of the attribute values; constructing an attribute declaration mode corresponding to the format data according to the attribute values and the data types, obtaining an acquisition method and a storage method of the attribute values of the format data, and storing the attribute declaration mode, the acquisition method and the storage method into the string object; converting the string object into a target string, writing the target string into a target object file, and generating an interface document of a target format based on the target object file. Therefore, the problems that, in the related art, when different external interface documents are connected, a class file corresponding to a JSON format parameter of a connected interface needs to be generated in a handwritten mode, and the efficiency is low and the error rate is high are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a data format conversion method, apparatus, server, medium and computer program. Background Technology

[0002] Currently, the mainstream method for transmitting API documentation is through JSON format. When developers are working with related APIs, they often need to write the corresponding JSON files into corresponding Java class files. In related technologies, when developers are working with different external API documentation, they need to manually generate the corresponding class files by taking the JSON format parameters of the API, which results in low efficiency and high error rate. Summary of the Invention

[0003] This application provides a data format conversion method, apparatus, server, storage medium, and computer program to solve the problems of low efficiency and high error rate in related technologies when interfacing with different external interface documents, where the interface parameters are in JSON format and corresponding class files need to be generated manually.

[0004] The first aspect of this application provides a data format conversion method, including the following steps: creating a string object; storing the attribute values ​​of the format data to be converted into the string object, and identifying the data type of the attribute values; constructing the attribute declaration method corresponding to the format data based on the attribute values ​​and data types, and obtaining the acquisition method and storage method of the attribute values ​​of the format data, storing the attribute declaration method, acquisition method and storage method into the string object; converting the string object into a target string, writing the target string into a target object file, and generating an interface document of the target format based on the target object file.

[0005] Optionally, in one embodiment of this application, before converting the string object into the target string, the method further includes: constructing a preset class name and class file format data for the string object; and writing the preset class name and class file format data into the string object.

[0006] Optionally, in one embodiment of this application, the data type includes at least one of the following: array type, object type, regular type, and unknown type.

[0007] Optionally, in one embodiment of this application, if the data type is an object type, identifying the data type of the attribute value includes: identifying the attributes of the object corresponding to the object type and the attribute values ​​corresponding to the attributes; and determining the data type based on the attribute values.

[0008] Optionally, in one embodiment of this application, before storing the attribute value of the format data to be converted into a string object, the method further includes: obtaining the string input by the user; determining whether the string meets the preset format requirements; if it does, obtaining the string as the format data to be converted.

[0009] A second aspect of this application provides a data format conversion apparatus, comprising: a creation module for creating a string object; a first storage module for storing attribute values ​​of format data to be converted into the string object and identifying the data type of the attribute values; a second storage module for constructing an attribute declaration method corresponding to the format data based on the attribute values ​​and data type, obtaining the acquisition method and storage method of the attribute values ​​of the format data, and storing the attribute declaration method, acquisition method, and storage method into the string object; and a conversion module for converting the string object into a target string, writing the target string into a target object file, and generating an interface document of the target format based on the target object file.

[0010] Optionally, in one embodiment of this application, the data format conversion device further includes: a writing module, configured to construct a preset class name and class file format data of the string object before converting the string object into a target string; and to write the preset class name and class file format data into the string object.

[0011] Optionally, in one embodiment of this application, the data type includes at least one of the following: array type, object type, regular type, and unknown type.

[0012] Optionally, in one embodiment of this application, if the data type is an object type, the first writing module is further used to identify the attributes of the object corresponding to the object type and the attribute values ​​corresponding to the attributes; and to determine the data type based on the attribute values.

[0013] Optionally, in one embodiment of this application, the data format conversion device further includes: an acquisition module, configured to acquire a string input by the user before storing the attribute value of the format data to be converted into a string object; determine whether the string meets the preset format requirements; and if it does, acquire the string as the format data to be converted.

[0014] A third aspect of this application provides a server, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to perform the data format conversion method as described in the above embodiments.

[0015] A fourth aspect of this application provides a computer-readable storage medium having a computer program stored thereon, which is executed by a processor to perform the data format conversion method as described in the above embodiments.

[0016] A fifth aspect of this application provides a computer program product having a computer program or instructions stored thereon, which, when executed, implement the data format conversion method as described in any of the above embodiments.

[0017] Therefore, this application has at least the following beneficial effects:

[0018] This application embodiment can store the format data to be converted and the data type corresponding to the attribute values ​​into a string object, and automatically parse it into the file class corresponding to the format data to be converted. This prevents developers from omitting attribute values, writing incorrect attribute values, or misinterpreting attribute types when converting the format data to be converted into class files, thus improving the efficiency of developers in generating relevant class files when interfacing with documentation interfaces. Therefore, it solves the problem in related technologies where developers need to manually generate corresponding class files by writing JSON format parameters for the interface when interfacing with different external interface documents, resulting in low efficiency and high error rates.

[0019] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0020] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein:

[0021] Figure 1 This is a flowchart of a data format conversion method provided according to an embodiment of this application;

[0022] Figure 2 This is an example diagram illustrating data format conversion according to an embodiment of this application;

[0023] Figure 3 This is an example diagram of a data format conversion method apparatus according to an embodiment of this application;

[0024] Figure 4 This is a schematic diagram of the server structure provided in an embodiment of this application. Detailed Implementation

[0025] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application.

[0026] The following description, with reference to the accompanying drawings, outlines a data format conversion method, apparatus, server, medium, and computer program according to embodiments of this application. Addressing the problems mentioned in the background section, this application provides a data format conversion method. In this method, the data to be converted and the data types corresponding to the attribute values ​​are stored in a string object, which is then automatically parsed into a file class corresponding to the data to be converted. This prevents developers from omitting attribute values, writing incorrect attribute values, or misinterpreting attribute types when converting the data to be converted into class files, thus improving the efficiency of developers in generating relevant class files when interfacing with documentation interfaces. This solves the problem in related technologies where developers need to manually generate corresponding class files from JSON format parameters of the interface when interfacing with different external interface documents, resulting in low efficiency and a high error rate.

[0027] Specifically, Figure 1 This is a flowchart illustrating a data format conversion method provided in an embodiment of this application.

[0028] like Figure 1 As shown, this data format conversion method includes the following steps:

[0029] In step S101, a string object is created.

[0030] In step S102, the attribute values ​​of the format data to be converted are stored in a string object, and the data type of the attribute values ​​is identified.

[0031] The data types include at least one of the following: array type, object type, regular type, and unknown type.

[0032] In actual implementation, the embodiments of this application can convert the formatted data to be converted into a JSON object (such as by converting it using the Jackson utility class), thereby obtaining all the attribute values ​​of the formatted data.

[0033] In one embodiment of this application, if the data type is an object type, identifying the data type of the attribute value includes: identifying the attributes of the object corresponding to the object type and the attribute values ​​corresponding to the attributes; and determining the data type based on the attribute values.

[0034] It is understood that the embodiments of this application can traverse the properties of the JSON object, query the value corresponding to the property value of the JSON string input by the developer based on the property value, determine which data types the current property value satisfies, construct a List if it is an array type, repeat the above operation if it is an object type, use the regular type if it is a regular type, and use the unknown type if it is initially represented by the String type, and inform the developer of the precautions.

[0035] In one embodiment of this application, before storing the attribute value of the format data to be converted into a string object, the method further includes: obtaining the string input by the user; determining whether the string meets the preset format requirements; if it does, obtaining the string as the format data to be converted.

[0036] The preset format requirement can be JSON format.

[0037] During software development, the data required for a project may come from different companies or different departments within the same company. Different data sources lead to different definitions of data formats. Currently, the mainstream way to transmit interface documents is through JSON format. This application embodiment can perform unified conversion processing for JSON format. First, it can check whether the current string meets the JSON format requirements. If it does not meet the requirements, it will inform the developers that the JSON format is incorrect.

[0038] In step S103, the attribute declaration method corresponding to the format data constructed according to the attribute value and data type is obtained, and the method for obtaining and storing the attribute value of the format data is obtained, and the attribute declaration method, the method for obtaining and the method for storing are stored in a string object.

[0039] In step S104, the string object is converted into a target string, and the target string is written to a target object file. An interface document in the target format is generated based on the target object file.

[0040] In this embodiment, the string object can be a StringBuilder object. This embodiment can construct a preset class name and class file format data for the StringBuilder object, construct the traversed attributes and data types into corresponding attribute declaration methods and construct the get and set methods of the attributes, and write the preset class name and class file format data required by the class file into the StringBuilder object in a consistent manner; wherein, the preset class name can be customized or selected by the user, without specific limitations.

[0041] Furthermore, the StringBuilder data is converted into a target string, a target object file (File object file) is constructed, and the string is written into the corresponding File object according to a custom path, along with the corresponding class file. Based on the class file, this embodiment can generate interface documents for various tool service classes, such as service classes, calling classes, and database table information related to that class. It also supports features such as secondary overwriting, adding, and deleting of data with the same format.

[0042] The following is combined Figure 2 The data format conversion method of this application embodiment will be described in detail, mainly including the following steps:

[0043] (1) First, check if the current string meets the JSON format type;

[0044] (2) Convert the string that meets the JSON format into a JSON object;

[0045] (3) Iterate through the properties of the JSON object and read the string properties and values, and determine the property type of the current property value;

[0046] (4) Create a StringBuilder object, and construct the traversed properties and types into the corresponding JAVA class property declaration method and the get and set methods of the property;

[0047] (5) Append custom class name and class file format data to the StringBuilder object, convert the data into a string, construct a File object file, write the string into the corresponding File object according to the custom path, and input the corresponding class file.

[0048] The data format conversion method proposed in this application stores the data to be converted and the data type corresponding to the attribute values ​​into a string object, and automatically parses it into the file class corresponding to the data to be converted. This prevents developers from omitting attribute values, writing incorrect attribute values, or misinterpreting attribute types when converting the data to be converted into class files, thus improving the efficiency of developers in generating relevant class files when interfacing with documentation interfaces. Therefore, it solves the problem of low efficiency and high error rate in related technologies where developers need to manually generate corresponding class files from JSON format parameters of the interface when interfacing with different external interface documents.

[0049] Next, the data format conversion apparatus proposed according to the embodiments of this application is described with reference to the accompanying drawings.

[0050] Figure 3 This is a block diagram of a data format conversion device according to an embodiment of this application.

[0051] like Figure 3 As shown, the data format conversion device 10 includes: a creation module 100, a first storage module 200, a second storage module 300, and a conversion module 400.

[0052] The creation module 100 is used to create string objects; the first storage module 200 is used to store the attribute values ​​of the format data to be converted into the string object and identify the data type of the attribute values; the second storage module 300 is used to construct the attribute declaration method corresponding to the format data according to the attribute values ​​and data types, obtain the acquisition method and storage method of the attribute values ​​of the format data, and store the attribute declaration method, acquisition method and storage method into the string object; the conversion module 400 is used to convert the string object into the target string, write the target string into the target object file, and generate the target format interface document based on the target object file.

[0053] In one embodiment of this application, the data format conversion device 10 further includes: a writing module, configured to construct a preset class name and class file format data of the string object before converting the string object into a target string; and to write the preset class name and class file format data into the string object.

[0054] In one embodiment of this application, the data type includes at least one of the following: array type, object type, regular type, and unknown type.

[0055] In one embodiment of this application, if the data type is an object type, the first writing module 200 is further used to identify the attributes of the object corresponding to the object type and the attribute values ​​corresponding to the attributes; and to determine the data type based on the attribute values.

[0056] In one embodiment of this application, the data format conversion device 10 further includes: an acquisition module, configured to acquire a string input by the user before storing the attribute value of the format data to be converted into a string object; determine whether the string meets the preset format requirements, and if it does, acquire the string as the format data to be converted.

[0057] It should be noted that the foregoing explanation of the data format conversion method embodiment also applies to the data format conversion device of this embodiment, and will not be repeated here.

[0058] The data format conversion device proposed in this application stores the data to be converted and the data type corresponding to the attribute values ​​into a string object, and automatically parses it into the file class corresponding to the data to be converted. This prevents developers from omitting attribute values, writing incorrect attribute values, or misinterpreting attribute types when converting the data to be converted into class files, thus improving the efficiency of developers in generating relevant class files when interfacing with documentation interfaces. Therefore, it solves the problem in related technologies where developers need to manually generate corresponding class files by writing JSON format parameters for the interface when interfacing with different external interface documents, resulting in low efficiency and high error rates.

[0059] Figure 4A schematic diagram of the structure of a server provided in an embodiment of this application. The server may include:

[0060] The memory 401, the processor 402, and the computer program stored on the memory 401 and capable of running on the processor 402.

[0061] When the processor 402 executes the program, it implements the data format conversion method provided in the above embodiments.

[0062] Furthermore, the server also includes:

[0063] Communication interface 403 is used for communication between memory 401 and processor 402.

[0064] The memory 401 is used to store computer programs that can run on the processor 402.

[0065] The memory 401 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.

[0066] If the memory 401, processor 402, and communication interface 403 are implemented independently, then the communication interface 403, memory 401, and processor 402 can be interconnected via a bus to complete communication between them. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized into address buses, data buses, control buses, etc. For ease of representation, Figure 4 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0067] Optionally, in a specific implementation, if the memory 401, processor 402, and communication interface 403 are integrated on a single chip, then the memory 401, processor 402, and communication interface 403 can communicate with each other through an internal interface.

[0068] Processor 402 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.

[0069] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the data format conversion method described above.

[0070] This application also provides a computer program product having a computer program or instructions stored thereon, which, when executed, implement the data format conversion method as described in any of the above embodiments.

[0071] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0072] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "N" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0073] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or N executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.

[0074] It should be understood that the various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, the N steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or more of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0075] Those skilled in the art will understand that all or part of the steps of the methods described in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it includes one or a combination of the steps of the method embodiments.

Claims

1. A data format conversion method characterized by, The method comprises the following steps: creating a string object; storing attribute values of format data to be converted into the string object, and identifying data types of the attribute values; constructing an attribute declaration mode corresponding to the format data according to the attribute values and the data types, and obtaining an obtaining method and a storage method of the attribute values of the format data, and storing the attribute declaration mode, the obtaining method and the storage method into the string object; converting the string object into a target string, and writing the target string into a target object file, and generating an interface document of a target format based on the target object file; before converting the string object into the target string, further comprising: constructing a preset class name and class file format data of the string object; writing the preset class name and the class file format data into the string object.

2. The data format conversion method according to claim 1, characterized by, The data types comprise at least one of an array type, an object type, a general type and an unknown type.

3. The data format conversion method of claim 2, wherein, If the data type is the object type, the identifying the data types of the attribute values comprises: identifying attributes of an object corresponding to the object type and attribute values corresponding to the attributes; determining the data types according to the attribute values.

4. The data format conversion method of claim 1, wherein, Before storing the attribute values of the format data to be converted into the string object, further comprising: obtaining a string input by a user; judging whether the string meets preset format requirements, and if yes, obtaining the string as the format data to be converted.

5. A data format conversion apparatus characterized by comprising: The method comprises: creating a module for creating a string object; a first storing module for storing attribute values of format data to be converted into the string object, and identifying data types of the attribute values; a second storing module for constructing an attribute declaration mode corresponding to the format data according to the attribute values and the data types, and obtaining an obtaining method and a storage method of the attribute values of the format data, and storing the attribute declaration mode, the obtaining method and the storage method into the string object; a converting module for converting the string object into a target string, and writing the target string into a target object file, and generating an interface document of a target format based on the target object file; a writing module for, before converting the string object into the target string, constructing a preset class name and class file format data of the string object, and writing the preset class name and the class file format data into the string object.

6. A server, characterized by The method comprises: a memory, a processor and a computer program stored in the memory and executable on the processor, the processor executing the computer program to implement the data format conversion method according to any one of claims 1-4.

7. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the data format conversion method according to any one of claims 1-4.

8. A computer program product having stored thereon a computer program or instructions, characterized in that, The computer program or instructions are executed to implement the data format conversion method according to any one of claims 1-4.

Citation Information

Patent Citations

  • Data format conversion method and system, medium and electronic equipment

    CN110222008A

  • Software development kit code generation method and device, equipment and storage medium

    CN115291851A