CN117950637A - Method, device, electronic equipment and storage medium for serializing objects - Google Patents

Method, device, electronic equipment and storage medium for serializing objects Download PDF

Info

Publication number
CN117950637A
CN117950637A CN202311055406.5A CN202311055406A CN117950637A CN 117950637 A CN117950637 A CN 117950637A CN 202311055406 A CN202311055406 A CN 202311055406A CN 117950637 A CN117950637 A CN 117950637A
Authority
CN
China
Prior art keywords
field
target
field information
information
type
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311055406.5A
Other languages
Chinese (zh)
Inventor
王育锋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Mashang Xiaofei Finance Co Ltd
Original Assignee
Mashang Xiaofei Finance Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Mashang Xiaofei Finance Co Ltd filed Critical Mashang Xiaofei Finance Co Ltd
Priority to CN202311055406.5A priority Critical patent/CN117950637A/en
Publication of CN117950637A publication Critical patent/CN117950637A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Stored Programmes (AREA)

Abstract

The embodiment of the application provides a method, a device, electronic equipment and a storage medium for serializing objects, and relates to the technical field of software. The method comprises the following steps: acquiring at least one field information corresponding to a target object, wherein the field information comprises a field type; converting the field information according to the field type to obtain target field information corresponding to each field information; and splicing the target field information to obtain the serialization information of the target object. By adopting the scheme, the information contained in the instantiated object can be converted into the easily readable and concise serialization information, the readability of the serialization information is improved, and the application of users of non-software field professionals is facilitated.

Description

Method, device, electronic equipment and storage medium for serializing objects
Technical Field
The present application relates to the field of software technologies, and in particular, to a method, an apparatus, an electronic device, and a storage medium for object serialization.
Background
In the field of object-oriented programming software technology, an instantiated object includes rich information, and the information contained in the instantiated object can be generally converted into a form that can be stored or transmitted, and this process is generally called serialization.
The serialized object information can have wide application, but the current object serialized object information is not friendly to users who are not professionals in the software field.
Disclosure of Invention
The embodiment of the application aims to provide a method, a device, electronic equipment and a storage medium for serializing objects.
In order to solve the above technical problems, embodiments of the present application are achieved by the following aspects.
According to a first aspect of embodiments of the present disclosure, there is provided a method of object serialization, the method comprising:
Acquiring at least one field information corresponding to a target object, wherein the field information comprises a field type;
converting the field information according to the field type to obtain target field information corresponding to each field information;
and splicing the target field information to obtain the serialization information of the target object.
According to a second aspect of embodiments of the present disclosure, there is provided an apparatus for object serialization, comprising:
The acquisition module is configured to acquire at least one field information corresponding to the target object, wherein the field information comprises a field type;
The conversion module is configured to convert the field information according to the field type to obtain target field information corresponding to each field information;
and the serialization module is configured to splice the target field information to obtain the serialization information of the target object.
In a third aspect, an embodiment of the present application provides an electronic device, including: the system comprises a memory, a processor and computer executable instructions stored on the memory and capable of running on the processor, wherein the computer executable instructions realize the steps when executed by the processor, of acquiring at least one field information corresponding to a target object, wherein the field information comprises a field type; converting the field information according to the field type to obtain target field information corresponding to each field information; and splicing the target field information to obtain the serialization information of the target object.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, perform steps of obtaining at least one field information corresponding to a target object, the field information including a field type; converting the field information according to the field type to obtain target field information corresponding to each field information; and splicing the target field information to obtain the serialization information of the target object.
The technical scheme provided by the embodiment of the disclosure is as follows: firstly, at least one piece of field information corresponding to a target object is acquired, wherein the field information comprises a field type; converting the field information according to the field type to obtain target field information corresponding to each field information; and splicing the target field information to obtain the serialization information of the target object. By adopting the scheme, the information contained in the instantiated object can be converted into the easily readable and concise serialization information, the readability of the serialization information is improved, and the application of users of non-software field professionals is facilitated.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Additional features and advantages of the present disclosure will be set forth in the detailed description which follows.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments described in the present application, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a method for serializing objects according to an embodiment of the present application;
FIG. 2 is a schematic flow chart of another method for serializing objects according to an embodiment of the present application;
FIG. 3 is a schematic flow chart of another method for serializing objects according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an apparatus for object serialization according to an embodiment of the present application;
fig. 5 is a schematic hardware structure of an electronic device for executing the method for serializing objects according to the embodiment of the present application.
Detailed Description
In order to make the technical solution of the present application better understood by those skilled in the art, the technical solution of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, shall fall within the scope of the present application.
Taking Java objects as an example, the Java objects after serialization can be represented as various forms of object information, such as Json or XML, whichever form of serialization information is poor in readability due to various reasons, such as the field names are generally english, the specific meaning of which is not easily understood, the field values in the serialization information are generally code values, such as 0,1,2, etc., and Json and XML generally contain some strict and specialized characters for precisely describing the structure thereof, which is also redundant to those skilled in the non-software art.
Firstly, describing the application scenario of the present application, in the service scenario, there is often an application scenario where the serialization information of the objects in the application service system exists, the user applying the serialization information is not usually a professional technician in the software field, such as a case call agent, in the case investigation process, the serialization information of the objects in the application service system is required, and the readability of the usual serialization information is poor, taking Json as an example, the information after the usual serialization is as follows:
{ "deptCode": "D001", "deptId":1, "deptName": technical part "," deptType ":
"TECH", "emps": [ { "empCode": "11111", "empId":20121111 "," empName ":" Zhang Sano "," leader ": true }," sons ": [ {" deptCode ":" D0011"," deptId ": 2", "deptName": "wind control research and development portion", "deptType": "TECH", "emps": [ { empCode ":"22222"," empId ": 20132222", "empName": four "," leader ": true }, {" empCode ": 33333", "empId":20143333 "," empName ":" king five "," leader ": false, {" contact ": {" name ": zhao Liu": phone ": 11111111111 } } ] }
Poor readability results from various reasons, which greatly reduces the efficiency of the user's work with the serialized information.
According to the technical scheme provided by the application, the information contained in the instantiated object can be converted into the easily readable and concise serialization information, the readability of the serialization information is improved, and the application of users of professionals in non-software fields is facilitated.
The following description is made with reference to specific examples.
Fig. 1 is a schematic flow chart of a method for serializing an object, which is provided in an embodiment of the present application, and the method may be performed by an electronic device, for example, a terminal device or a server device. In other words, the method may be performed by software or hardware installed at a terminal device or a server device. The service end includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, and the like. As shown in fig. 1, the method may include the following steps.
In step S10, at least one field information corresponding to the target object is acquired.
Wherein the field information includes a field type.
In object-oriented programming, an object is typically obtained by instantiating a class defined in a program, and field definitions in the object may be derived from definitions of the class or inherited from a parent class by the class. The field information may include a plurality of field types.
The field types may include a base type, an object type, or a special type. Taking Java as an example, the base type may include a logical type (e.g., bootean), an integer type (e.g., byte, short, int, long), a character type (e.g., char), a floating point type (e.g., float, double), an object type characterizes the field as a child object, a special type may include a collection type, an enumeration type, and a string type, and a special type may also include a sensitive field type annotated with Mask.
For the different field types, corresponding strategies can be adopted to obtain target field information corresponding to the field information in a targeted manner.
In some possible implementations, in the case that the target object is a Java object, at least one field information corresponding to the target object may be obtained through a Java reflection mechanism. The Java reflection mechanism is a reflection mechanism that can call the method and attribute of any object in the running state, for example, at least one attribute information obtained by the Java reflection mechanism can be used as the field information, and the function of dynamically calling the object is called Java.
Those skilled in the art will appreciate that, for other programming languages, a mechanism similar to the Java language may be used to obtain at least one field information corresponding to the target object through programming. The present application is not limited to a particular programming language.
In step S20, the field information is converted according to the field type, so as to obtain the target field information corresponding to each field information.
After obtaining at least one field information corresponding to the target object, each field information may be sequentially converted into corresponding target field information.
For different field types, the field information can be converted by adopting the same or different technical modes to obtain corresponding target field information. For example, 'deptCode': 'D001' "is converted to '" department code': 'D001' ".
In step S30, the target field information is spliced to obtain the serialization information of the target object.
After the target field information corresponding to each field information is obtained, in order to further improve the readability of the serialization information, the target field information can be spliced through a preset first splice symbol to obtain the serialization information of the target object.
The first splice may be a summarizer (for example, a bracket, a middle bracket, or a bracket) that jointly represents related target field information, a separator (for example, a comma, a break, or a semicolon) of different target field information, or a layering (for example, a indenter, a line feed, or a tab) that represents target field information of different layers, and the application does not limit the type of the first splice.
Illustratively, the converted and spliced serialization information may be:
department code D001, department name, department type, department technology, staff list [ work number 11111, name Zhang San, whether leading is;
The lower level department [ department code: D0011, department name: wind control research and development department, department type: technical department, staff list [ job number: 22222, name: li four, whether leading is; work No. 33333, name: wangwu, no. leadership, emergency contact: [ name: zhao Liu, phone: 11111111111 ]
By adopting the mode, the information contained in the instantiated object can be converted into the easily readable and concise serialization information, the readability of the serialization information is improved, and the application of users of non-software field professionals is facilitated.
Fig. 2 is a schematic flow chart of another method for serializing an object according to an embodiment of the present application, as shown in fig. 2, where the field information further includes a field name and a field value, the target field information includes a target field name and a target field value, and step S20 may include the following sub-steps:
In step S201, the field name is converted according to the field type, to obtain the target field name.
For example, still taking a Java object as an example, a field description corresponding to the field name may be obtained through at least one of ApiModelProperty notes, column notes, command notes, and HumanField notes, and the field description is taken as the target field name. Taking ApiModelProperty notes as an example, apiModelProperty notes are notes that act on the attributes (fields) of the interface-related entity class, and can be used to add and obtain additional descriptive information to the parameters of a particular interface-related entity class. The technical solution for acquiring the field description specifically through ApiModelProperty is described in the related art, and will not be described in detail herein.
In some possible implementations, the multiple ways of obtaining the target field name may be ordered according to a preset priority, and the field description obtained by the annotation mode with the highest priority is used as the target field name.
In step S202, the field value is converted according to the field type and the field name, so as to obtain the target field value.
In some possible implementations, the field value may be converted according to the field type and the field name for different field types, to obtain the target field value.
Those skilled in the art will appreciate that the type of field value may be the same as or different from the type of target field value, for example: the sex "1" of the character type may correspond to "woman" of the character type, and the department id "1" of the number type may correspond to "technical part" of the character string type.
For example, in the case where the field type is a logical type (e.g., bootean), the field value may be converted according to the following table to obtain the target field value.
Field value Target field value
True Is that
False Whether or not
List one
Taking the target object as a Java object as an example, in the case that the field type is an enumeration type (for example IEnum), the target field value corresponding to the field value can be obtained by calling the getMsg method.
In the case that the field type is an integer type (e.g. byte, short, int, long) or a floating point type (e.g. float, double), the field value can be converted by a preset conversion method to obtain a target field value corresponding to the field value, where the conversion method can be, for example, a preset corresponding relation table, a preset calculation logic, or a preset statistics logic.
In step S203, the destination field name and the destination field value are spliced to obtain destination field information.
After the target field name and the target field value are obtained, in order to further improve the readability of the serialization information, the target field name and the target field value can be spliced through a preset second splice symbol to obtain the target field information.
Illustratively, the second splice may be a colon, for example, in the case where the destination field name is "name" and the destination field value is "Zhao Liu", the destination field information may be "name: zhao Liu% by weight of a metal alloy.
By adopting the mode, the information contained in the instantiated object can be converted into the easily readable and concise serialization information, the readability of the serialization information is improved, and the application of users of non-software field professionals is facilitated.
In some embodiments, the field type may be a collection type, and the field information may include a plurality of elements, for example, each element may be a subfield of the collection, for example, a computer asset of a department may form an asset collection, and the step S202 may include the following substeps:
and step 11, if the field type is the set type, converting the field name according to the field type to obtain the set field name.
For example, still taking the target object as a Java object as an example, a field description corresponding to a field of the collection type may be obtained through at least one of ApiModelProperty notes, column notes, command notes, and HumanField notes, and the field description is taken as a collection field name.
Step 12, obtaining first sub-field information in the target set. The target set comprises a plurality of first sub-field information corresponding to field values in the field information.
For example: in the asset set of a certain department, each piece of sub-field information comprises an asset number corresponding to one computer asset of the department, and a plurality of pieces of sub-field information form the asset set of the department.
In some possible implementations, in a case that the target object is a Java object, the plurality of first subfield information may be acquired by means of Java reflection.
And 13, converting the first sub-field information according to the field type of the first sub-field information to obtain first target sub-field information corresponding to each piece of first sub-field information, and splicing the first target sub-field information to obtain set field information corresponding to a target set.
Illustratively, for the set { propertyID:11111111, propertyid:22222222, propertyid:33333333}, can be converted into aggregate field information [ asset number: 11111111, asset number: 22222222, asset number: 33333333 ] are provided. It will be understood by those skilled in the art that the above target set may further include a set of a further layer, and in a similar manner to the present embodiment, set field information corresponding to each set of a further layer may be obtained in a recursive manner, and field information corresponding to the set of a further layer is used as the target field information of the corresponding first subfield information. And then splicing the target field information to obtain the integrated field information.
Illustratively, the aggregate {propertyID:11111111,multiproperty:{propertysubID:11112222,propertysubID:22223333},propertyID:33333333}, may be converted to aggregate field information [ asset number ] by the steps described above: 11111111, composite asset [ child asset number: 11112222, child asset number: 22223333, asset number: 33333333 ] are provided.
And 14, splicing the set field names and the set field information, and determining target field information corresponding to the target set.
For example, the set field name and the set field information may be spliced according to a preset third splice symbol, so as to determine target field information corresponding to the target set.
The third splice may be, for example, a summarizer (e.g., a small bracket, a middle bracket, or a large bracket) that jointly represents the related target field information, and the present application is not limited to the third splice.
For example, the target field information corresponding to the asset collection after the splicing is completed may be:
list of assets: asset number: 11111111, asset number: 22222222, asset number: 33333333 @.
By adopting the technical mode, each piece of first sub-field information of the set can be traversed, so that the target field information corresponding to the field information of the set type is obtained, the information contained in the instantiated object can be converted into easy-to-read and simple serialization information, the readability of the serialization information is improved, and the application of users of non-software field professionals is facilitated.
In some embodiments, the field type may be an object type, for example, a department object includes field information of a department name, a department type, a department person, and the like, and may also include a sub-department, which may be a next-level department object. The above step S202 may include the following substeps.
And step 21, if the field type is the object type, converting the field name according to the field type to obtain the object field name.
For example, still taking the target object as a Java object as an example, a field description corresponding to a field of the object type may be obtained through at least one of ApiModelProperty notes, column notes, command notes, and HumanField notes, and the field description may be used as the object field name.
Step 22, obtaining second sub-field information corresponding to the target sub-object, where the target sub-object includes a sub-object corresponding to a field value in the field information, and the target sub-object may include at least one piece of second sub-field information.
For example, the wind control development part under the technical part is a sub-object corresponding to the technical part, and the wind control development part may include second sub-field information such as a department code, a department name, and a department type.
And 23, converting the second sub-field information according to the field type of the second sub-field information to obtain second target sub-field information corresponding to each piece of second sub-field information, and splicing the second target sub-field information to obtain object field information corresponding to the target sub-object.
It will be understood by those skilled in the art that the above target sub-object may further include a sub-object of a further layer, for example, the wind control development part under the technical jurisdiction may further include at least one subordinate sub-division, and in a similar manner to the present embodiment, the object field information corresponding to each sub-object of the further layer may be obtained in a recursive manner, and the field information corresponding to the sub-object of the further layer is used as the target field information of the corresponding second sub-field information. And then splicing the target field information to obtain the target field information.
For example, the target sub-object includes a wind control development part, the wind control development part may further include a wind control development group and a wind control development group, where the wind control development group and the wind control development group are sub-objects of a deeper layer under the wind control development part, and the above manner may be adopted to obtain the target field information intended by the target sub-object as follows:
[ department code: d0011, department name: wind control research and development department, department type, technical department, lower level department: [ department code: d00111, department name: wind control research and development group, department type: technical department) lower departments: [ department code: d00112, department name: wind control research and development are two groups, department types are technical department.
And step 24, splicing the object field name and the object field information to determine the target field information corresponding to the target sub-object.
And splicing the object field name and the object field information according to a preset fourth splice sign, and determining target field information corresponding to the target sub-object. The fourth splice may be, for example, a colon.
For example, after the object field name and the object field information are spliced, the object field information corresponding to the wind control development part can be obtained as follows:
The lower level department [ department code: D0011, department name: wind control research and development department, department type: technical department, staff list [ job number: 22222, name: li four, whether leading is; work number 33333, name five, whether leading, no, emergency contact person [ name Zhao Liu, phone 11111111111 ].
By adopting the technical mode, the target field information corresponding to the field information of the object type can be obtained, the information contained in the instantiated object can be converted into the easily readable and concise serialization information, the readability of the serialization information is improved, and the application of users of professionals in the non-software field is facilitated.
It will be appreciated by those skilled in the art that field information of different types may be nested in multiple layers, for example, sub-field information included in field information of a collection type may be of an object type, or of course, may be of a collection type, an enumeration type, or a base type. The sub-field information included in the field information of the object type may also be an aggregate type, or of course, an object type, an enumeration type or a basic type, and in the case that the sub-field information is an aggregate type or an object type, the target field information corresponding to the next level of aggregate type or object type may be acquired with reference to steps 11-14 or 21-24, and the target field information corresponding to other sub-field information may be spliced to obtain final target field information.
Illustratively, the target sub-object includes a wind research and development part, wherein the employee list is a field of a collection type, the information of a plurality of employees is included below the field of the collection type, and a further collection (such as emergency contact information) can be included in the collection. In some possible embodiments, the target field information of each employee in the employee list may be obtained in a recursive manner, and then spliced into the aggregate field information "[ job number: 22222, name: li four, whether or not the leader is; the method comprises the steps of (1) forming target field information corresponding to an employee list set after splicing an aggregate field name of 'employee list', and then splicing target field information corresponding to a plurality of second sub-field information (department codes, department names and department types) in a target sub-object to obtain the target field information of the target sub-object, wherein the work number is 33333, the name is five, and whether an emergency contact is leaded or not, the name is Zhao Liu, and the phone is 11111111111:
[ department code: D0011, department name: wind control research and development department, department type: technical department, staff list: [ job number: 22222, name: lifour, whether leading is; work number 33333, name five, whether leading, no, emergency contact person [ name Zhao Liu, phone 11111111111 ].
In some embodiments, the field type may be a sensitive field type, where the sensitive field characterizes information corresponding to the sensitive field that needs to be encrypted, for example, may be sensitive information that is not plainly exposable.
The step S202 may include:
And performing desensitization conversion treatment on the field value according to the field name to obtain the target field value.
Still taking the target object as a Java object as an example, whether the field type is a sensitive field type can be determined through Mask annotation, and under the condition that the field type is the sensitive field type, the field value can be subjected to desensitization conversion processing according to the field name and a preset desensitization processing strategy to obtain the target field value.
The specific desensitization treatment strategy can be referred to the technical scheme in the related technology, and is not described in detail herein.
In some embodiments, the field type may also be a string type, and the step S202 may include the following sub-steps:
And converting the field value according to the preset code table corresponding relation to obtain a target field value under the condition that the preset code table corresponding relation comprises the field name, or taking the field value as the target field value under the condition that the preset code table corresponding relation does not comprise the field name, wherein the preset code table corresponding relation comprises at least one group of corresponding relations of the field name and the conversion method.
For example, the field name may be "deptType", the field value may be "TECH", and when the field name is converted into the target field name "department name", the field value may be converted through the corresponding relationship of the code table shown in the table two, to obtain the target field value "technical part".
Watch II
And the field name is 'deptCode', the field value is 'D0011', after the field name is converted into the target field name 'department code', the field value 'D0011' can be used as the target field value because the code table corresponding relation does not contain the field name 'deptCode'.
Those skilled in the art will appreciate that the above-described code table correspondence may take a variety of flexible implementations, such as a field value or a many-to-one relationship with a target field value. The target field value may also be a processing logic definition that processes the field value. The application is not limited in this regard.
Under the condition that the field type is a character type (for example char), the field value can be converted similarly to the corresponding relation of the preset code table shown in the second table, and the target field value corresponding to the field value is obtained.
By adopting the technical mode, the information contained in the instantiated object can be converted into the easily readable and concise serialization information, the readability of the serialization information is improved, and the application of users of professionals in non-software fields is facilitated.
In some embodiments, the field information may further include a modifier, and in the case that the field information includes a preset modifier, the step of obtaining the target field name corresponding to the field information may be skipped. Taking the Java object as an example, the preset modifier may include final, static, or transient. The final characterizes the field as a constant, the static characterizes the field as a static variable, the transient characterizes the key word in Java serialization, the field corresponding to the preset modifier characterizes the key information which does not include serialization, and the step of obtaining the target field name corresponding to the field information can be skipped, so that the efficiency of obtaining the serialization information of the target object is further improved.
In another embodiment, in the case that the field type is the object type, the field information of the object type may be analyzed.
Illustratively, taking the target object (or target sub-object) as a Java object for example, it may be determined whether the target object (or target sub-object) contains valid information in at least one of the following ways, and in the case where the target object (or target sub-object) does not contain valid information, the processing of the target object (or target sub-object) is skipped.
In the first mode, whether the package of the class of the defined target object (or the target sub-object) is in a preset entity class package is determined.
And in the second mode, the instanceof keywords are adopted to determine whether the target object (or the target sub-object) is a preset interface implementation class.
By adopting the mode, the field information of the object type which does not contain effective information can be filtered, so that the efficiency of acquiring the serialization information of the target object is further improved.
Fig. 3 is another flow chart of a method for serializing an object according to an embodiment of the present application, and as shown in fig. 3, the method may include the following steps.
In step S301, the type of the target object is acquired.
Taking a target object as a Java object as an example, the type of the target object can be obtained through a reflection API.
In step S302, at least one field information corresponding to the target object is acquired.
In some possible implementations, in the case that the target object is a Java object, at least one field information corresponding to the target object may be obtained through a Java reflection mechanism according to a type of the target object.
In step S303, a field list composed of field information is circularly processed.
In some possible implementations, the field information in the field list may be sequentially processed, and when the field type is the object type or the set type, the step 11-14 or the step 21-24 may be further referred to obtain the target field information corresponding to the field information of the set type or the object type.
In step S304, it is confirmed whether or not the current field information needs to be output.
For example, the field information may include a modifier, and in the case where the field information includes a preset modifier, the step of acquiring the target field name corresponding to the field information may be skipped. Taking the Java object as an example, the preset modifier may include final, static, or transient. The final representation field is a constant, the static representation field is a static variable, the transient representation field is a keyword in Java serialization, the preset modifier representation field does not include the key information of serialization, and the field information can be skipped to obtain, so that the efficiency of obtaining the serialization information of the target object is further improved.
In step S305, conversion of the field name and the field value is performed.
For example, still taking a Java object as an example, a field description corresponding to the field name may be obtained through at least one of ApiModelProperty notes, column notes, command notes, and HumanField notes, and the field description is taken as the target field name. Taking ApiModelProperty notes as an example, apiModelProperty notes are notes that act on the attributes (fields) of the interface-related entity class, and can be used to add and obtain additional descriptive information to the parameters of a particular interface-related entity class. The technical solution for acquiring the field description specifically through ApiModelProperty is described in the related art, and will not be described in detail herein.
When the field value is converted, the field value can be converted by classification, and the specific conversion method is not expanded here.
And respectively obtaining the corresponding target field name and the target field value through conversion of the field name and the field value.
In step 306, the target field information is spliced.
The target field name and the target field value are spliced to obtain target field information, and in order to further increase readability, splice symbols can be added when splicing is performed, and the definition of a specific splice symbol can be set by itself according to needs, so that the method is not limited.
In step 307, it is determined whether all field information is traversed.
In the case where all the field information has not been completed by the traversal, the steps of steps S303 to S306 are repeated until all the field information is completed by the traversal.
In step 308, the target field information is spliced to obtain the serialized information.
When splicing is performed, splice symbols can be added, and the definition of specific splice symbols can be set according to the needs, so that the method is not limited.
By adopting the technical mode, the information contained in the instantiated object can be converted into the easily readable and concise serialization information, the readability of the serialization information is improved, and the application of users of professionals in non-software fields is facilitated.
Fig. 4 is a schematic structural diagram of an apparatus for object serialization according to an embodiment of the present application, as shown in fig. 4, the apparatus 100 includes: an acquisition module 110, a conversion module 120, and a serialization module 130.
An obtaining module 110, configured to obtain at least one field information corresponding to the target object, where the field information includes a field type;
The conversion module 120 is configured to convert the field information according to the field type to obtain target field information corresponding to each field information;
the serialization module 130 is configured to splice the target field information to obtain the serialization information of the target object.
Optionally, the field information further includes a field name and a field value; the conversion module 120 is further configured to:
converting the field name according to the field type to obtain a target field name;
Converting the field value according to the field type and the field name to obtain a target field value;
and splicing the target field name and the target field value to obtain target field information.
Optionally, the conversion module 120 is further configured to:
If the field type is the set type, converting the field name according to the field type to obtain the set field name;
Acquiring first sub-field information in a target set, wherein the target set comprises a plurality of first sub-field information corresponding to field values in the field information;
Converting the first sub-field information according to the field type of the first sub-field information to obtain first target sub-field information corresponding to each piece of first sub-field information, and splicing the first target sub-field information to obtain set field information corresponding to a target set;
and splicing the set field names and the set field information to determine target field information corresponding to the target set.
Optionally, the conversion module 120 is further configured to:
if the field type is the object type, converting the field name according to the field type to obtain the object field name;
acquiring second sub-field information corresponding to a target sub-object, wherein the target sub-object comprises sub-objects corresponding to field values in the field information, and the target sub-object comprises at least one piece of second sub-field information;
Converting the second sub-field information according to the field type of the second sub-field information to obtain second target sub-field information corresponding to each piece of second sub-field information, and splicing the second target sub-field information to obtain object field information corresponding to the target sub-object;
and splicing the object field name and the object field information, and determining target field information corresponding to the target sub-object.
Optionally, the field type is a sensitive field type, and the conversion module 120 is further configured to:
And performing desensitization conversion treatment on the field value according to the field name to obtain the target field value.
Optionally, the field type is a string type, and the conversion module 120 is further configured to:
Under the condition that the corresponding relation of the preset code table comprises a field name, converting the field value according to the corresponding relation of the preset code table to obtain a target field value; or alternatively
And under the condition that the preset code table corresponding relation does not comprise a field name, taking the field value as a target field value, wherein the preset code table corresponding relation comprises at least one group of corresponding relations of the field name and a conversion method.
Optionally, the apparatus 100 is applied to serialization of Java objects, and the obtaining module 110 is further configured to:
and acquiring at least one field information corresponding to the target object through a Java reflection mechanism.
The apparatus 100 provided in the embodiment of the present application may perform the methods described in the foregoing method embodiments, and implement the functions and beneficial effects of the methods described in the foregoing method embodiments, which are not described herein again.
Fig. 5 shows a schematic diagram of a hardware structure of an electronic device provided by an embodiment of the application, and referring to the figure, at a hardware level, the electronic device includes a processor, and optionally includes an internal bus, a network interface, and a memory. The Memory may include a Memory, such as a Random-Access Memory (RAM), and may further include a non-volatile Memory (non-volatile Memory), such as at least 1 disk Memory. Of course, the electronic device may also include hardware required for other services.
The processor, network interface, and memory may be interconnected by an internal bus, which may be an industry standard architecture (Industry Standard Architecture, ISA) bus, a peripheral component interconnect standard (PERIPHERAL COMPONENT INTERCONNECT, PCI) bus, or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, among others. The buses may be classified as address buses, data buses, control buses, etc. For ease of illustration, only one bi-directional arrow is shown in the figure, but not only one bus or one type of bus.
And a memory for storing the program. In particular, the program may include program code including computer-operating instructions. The memory may include memory and non-volatile storage and provide instructions and data to the processor.
The processor reads the corresponding computer program from the nonvolatile memory into the memory and then runs to form a device for locating the target user on a logic level. A processor executing the program stored in the memory, and specifically executing: the embodiments shown in fig. 1-3 disclose the method and implement the functions and advantages of the methods described in the foregoing method embodiments, which are not described in detail herein.
The methods disclosed above in the embodiments of the present application shown in fig. 1-3 may be implemented in or by a processor. The processor may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in a processor or by instructions in the form of software. The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but may also be a digital signal Processor (DIGITAL SIGNAL Processor, DSP), application SPECIFIC INTEGRATED Circuit (ASIC), field-Programmable gate array (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic device, discrete gate or transistor logic device, discrete hardware components. The disclosed methods, steps, and logic blocks in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present application may be embodied directly in the execution of a hardware decoding processor, or in the execution of a combination of hardware and software modules in a decoding processor. The software modules may be located in a random access memory, flash memory, read only memory, programmable read only memory, or electrically erasable programmable memory, registers, etc. as well known in the art. The storage medium is located in a memory, and the processor reads the information in the memory and, in combination with its hardware, performs the steps of the above method.
The electronic device may also execute the methods described in the foregoing method embodiments, and implement the functions and beneficial effects of the methods described in the foregoing method embodiments, which are not described herein.
Of course, other implementations, such as a logic device or a combination of hardware and software, are not excluded from the electronic device of the present application, that is, the execution subject of the following processing flows is not limited to each logic unit, but may be hardware or a logic device.
The embodiment of the present application further proposes a computer readable storage medium storing one or more programs that, when executed by an electronic device including a plurality of application programs, cause the electronic device to execute the method disclosed in the embodiment shown in fig. 1 to 3 and implement the functions and advantages of each method described in the foregoing method embodiment, which are not described herein again.
The computer readable storage medium includes Read-Only Memory (ROM), random access Memory (Random Access Memory RAM), magnetic disk or optical disk, etc.
Further, embodiments of the present application also provide a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, implement the following flow: the embodiments shown in fig. 1-3 disclose the method and implement the functions and advantages of the methods described in the foregoing method embodiments, which are not described in detail herein.
In summary, the foregoing description is only of the preferred embodiments of the present application, and is not intended to limit the scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the protection scope of the present application.
The system, apparatus, module or unit set forth in the above embodiments may be implemented in particular by a computer chip or entity, or by a product having a certain function. One typical implementation is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
Computer readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of storage media for a computer 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 Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium, which can store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or apparatus that comprises the element.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.

Claims (10)

1. A method of serializing objects, the method comprising:
Acquiring at least one field information corresponding to a target object, wherein the field information comprises a field type;
converting the field information according to the field type to obtain target field information corresponding to each field information;
and splicing the target field information to obtain the serialization information of the target object.
2. The method of claim 1, wherein the field information further comprises a field name and a field value, and the target field information comprises a target field name and a target field value; the converting the field information according to the field type to obtain target field information corresponding to each field information includes:
converting the field name according to the field type to obtain the target field name;
Converting the field value according to the field type and the field name to obtain the target field value;
And splicing the target field name and the target field value to obtain the target field information.
3. The method of claim 2, wherein the converting the field information according to the field type to obtain the target field information corresponding to each field information includes:
If the field type is a set type, converting the field name according to the field type to obtain a set field name;
Acquiring first sub-field information in a target set, wherein the target set comprises a plurality of pieces of first sub-field information corresponding to the field value in the field information;
Converting the first sub-field information according to the field type of the first sub-field information to obtain first target sub-field information corresponding to each piece of first sub-field information, and splicing the first target sub-field information to obtain set field information corresponding to the target set;
and splicing the set field names and the set field information to determine target field information corresponding to the target set.
4. The method according to claim 2, wherein the converting the field information according to the field type to obtain the target field information corresponding to each field information respectively includes:
if the field type is an object type, converting the field name according to the field type to obtain an object field name, wherein the object type representation field value comprises a sub-object;
acquiring second sub-field information corresponding to a target sub-object, wherein the target sub-object comprises sub-objects corresponding to the field values in the field information, and the target sub-object comprises at least one piece of second sub-field information;
Converting the second sub-field information according to the field type of the second sub-field information to obtain second target sub-field information corresponding to each piece of second sub-field information, and splicing the second target sub-field information to obtain object field information corresponding to the target sub-object;
And splicing the object field name and the object field information to determine the target field information corresponding to the target sub-object.
5. The method of claim 2, wherein the field type is a sensitive field type, the converting the field value according to the field type to obtain the target field value comprises:
and under the condition that the field type is a sensitive field type, performing desensitization conversion processing on the field value according to the field name to obtain the target field value.
6. The method according to claim 2, wherein the field type is a character string field type, the converting the field value according to the field type and the field name to obtain the target field value includes:
Under the condition that a preset code table corresponding relation comprises the field name, translating the field value according to the preset code table corresponding relation to obtain the target field value; or alternatively
And under the condition that the corresponding relation of the preset code table does not comprise the field names, taking the field values as the target field values, wherein the corresponding relation of the preset code table comprises the corresponding relation of the at least one group of field names and the translation method.
7. The method according to any one of claims 1 to 6, wherein the obtaining at least one field information corresponding to the target object is applied to serialization of Java objects, and includes:
and acquiring the at least one field information corresponding to the target object through a Java reflection mechanism.
8. An apparatus for serializing objects, comprising:
The acquisition module is configured to acquire at least one field information corresponding to the target object, wherein the field information comprises a field type;
The conversion module is configured to convert the field information according to the field type to obtain target field information corresponding to each field information respectively;
And the serialization module is configured to splice the target field information corresponding to the field information respectively to obtain the serialization information of the target object.
9. An electronic device, comprising:
A processor; and
A memory arranged to store computer executable instructions which, when executed, perform the steps of the method of object serialization of any one of claims 1 to 7 using the processor.
10. A computer readable storage medium storing one or more programs, which when executed by an electronic device comprising a plurality of application programs, cause the electronic device to perform the steps of the method of object serialization in any of claims 1-7.
CN202311055406.5A 2023-08-21 2023-08-21 Method, device, electronic equipment and storage medium for serializing objects Pending CN117950637A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311055406.5A CN117950637A (en) 2023-08-21 2023-08-21 Method, device, electronic equipment and storage medium for serializing objects

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311055406.5A CN117950637A (en) 2023-08-21 2023-08-21 Method, device, electronic equipment and storage medium for serializing objects

Publications (1)

Publication Number Publication Date
CN117950637A true CN117950637A (en) 2024-04-30

Family

ID=90793258

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311055406.5A Pending CN117950637A (en) 2023-08-21 2023-08-21 Method, device, electronic equipment and storage medium for serializing objects

Country Status (1)

Country Link
CN (1) CN117950637A (en)

Similar Documents

Publication Publication Date Title
CN106648569B (en) Target serialization realization method and device
CN109271611B (en) Data verification method and device and electronic equipment
CN109918678B (en) Method and device for identifying field meaning
CN113535817B (en) Feature broad table generation and service processing model training method and device
CN111597548B (en) Data processing method and device for realizing privacy protection
CN115952162A (en) Data quality checking method, device and equipment
CN112181924A (en) File conversion method, device, equipment and medium
CN110955658B (en) Data organization and storage method based on Java intelligent contract
CN105867886A (en) Method and device for writing table
CN109598478B (en) Wind measurement result description document generation method and device and electronic equipment
CN117950637A (en) Method, device, electronic equipment and storage medium for serializing objects
CN115983208A (en) Document conversion method and electronic equipment
CN113641708B (en) Rule engine optimization method, data matching method and device, storage medium and terminal
CN110018844B (en) Management method and device of decision triggering scheme and electronic equipment
CN109903165B (en) Model merging method and device
CN111882310B (en) Data comparison method, device and equipment and computer readable storage medium
CN111461346A (en) Network node characterization method, device and equipment
CN111311372A (en) User identification method and device
CN113535660B (en) Android log storage method and device
CN112101308B (en) Method and device for combining text boxes based on language model and electronic equipment
CN116128066A (en) Data enhancement method, model training method and device
CN113468258B (en) Heterogeneous data conversion method, heterogeneous data conversion device and storage medium
CN116861856A (en) Test case format conversion method, device, equipment and readable storage medium
US20240126988A1 (en) Word extraction device, word extraction system and word extraction method
CN113901822A (en) Entity recognition model establishing method, system, electronic device and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination