CN106648569B - Target serialization realization method and device - Google Patents

Target serialization realization method and device Download PDF

Info

Publication number
CN106648569B
CN106648569B CN201510735570.XA CN201510735570A CN106648569B CN 106648569 B CN106648569 B CN 106648569B CN 201510735570 A CN201510735570 A CN 201510735570A CN 106648569 B CN106648569 B CN 106648569B
Authority
CN
China
Prior art keywords
target
database
class
serialization
serialized
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.)
Active
Application number
CN201510735570.XA
Other languages
Chinese (zh)
Other versions
CN106648569A (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201510735570.XA priority Critical patent/CN106648569B/en
Publication of CN106648569A publication Critical patent/CN106648569A/en
Application granted granted Critical
Publication of CN106648569B publication Critical patent/CN106648569B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code

Abstract

The invention relates to a target serialization realization method and a target serialization realization device. The method comprises the following steps: automatically acquiring a part to be serialized in a target; analyzing the part to be serialized in the target to obtain an analysis result, and storing the analysis result; serializing the target according to the analysis result, and converting the serialized target into a packaging serialized wrapper; and calling the packaging serialization wrapper, and performing serialization reading and writing on the target through a reflection mechanism. According to the method and the device for realizing the target serialization, the part to be serialized in the target is automatically obtained and analyzed to obtain the analysis result, the target is serialized according to the analysis result and is converted into the packaging serialization packaging device, the packaging serialization packaging device and the reflection mechanism are called to perform serialization reading and writing, manual coding is not needed, the development efficiency is improved, manual copying and pasting are not needed, the defect is avoided, the quantity of engineering codes and the quantity of functions are reduced, and the space is reduced.

Description

Target serialization realization method and device
Technical Field
The invention relates to the field of computer application, in particular to a target serialization realization method and a target serialization realization device.
Background
The object serialization technique is a technique of converting object data into another persistent data form, and the data form after conversion must be easily stored on an external medium or easily transmitted using a network. Such a conversion must be reversible in order to enable the stored and transferred data to be transformed back to the object in memory again. The target serialization technology introduces the abstraction of an object in the data transmission and storage process, so that the process is more intuitive and more convenient to use, and therefore, the target serialization technology is widely used in an object-oriented software system.
Due to the wide application of the target serialization technology, a plurality of computing languages are in a language level, and the functional support of the target serialization, such as java language and the like, is provided in a standard library mode. In the Android system, reading and writing of target serialization codes are manually completed, for example, each time an object is added, the serialization codes are manually written in a database, however, a large number of functions and a large number of codes are repeated, and through manual copying and pasting, development efficiency is low, and defects are easily introduced due to manual copying and pasting.
Disclosure of Invention
Therefore, it is necessary to provide a target serialization implementation method, which can improve the development efficiency and avoid introducing defects, aiming at the problems that the development efficiency is low and defects are easily introduced due to manual copying and pasting of codes in the traditional target serialization process.
In addition, the target serialization realization device is provided, which can improve the development efficiency and avoid introducing defects.
A target serialization realization method comprises the following steps:
automatically acquiring a part to be serialized in a target;
analyzing the part to be serialized in the target to obtain an analysis result, and storing the analysis result;
serializing the target according to the analysis result, and converting the serialized target into a packaging serialized wrapper;
and calling the packaging serialization wrapper, and performing serialization reading and writing on the target through a reflection mechanism.
An object serialization realization apparatus, comprising:
the acquisition module is used for automatically acquiring a part to be serialized in the target;
the analysis module is used for analyzing the part to be serialized in the target to obtain an analysis result and storing the analysis result;
the conversion module is used for serializing the target according to the analysis result and converting the target into a packaging serialization wrapper;
and the calling module is used for calling the packaging serialization wrapper and performing serialization reading and writing on the target through a reflection mechanism.
According to the method and the device for realizing the target serialization, the part to be serialized in the target is automatically obtained and analyzed to obtain the analysis result, the target is serialized according to the analysis result and is converted into the packaging serialization packaging device, the packaging serialization packaging device and the reflection mechanism are called to perform serialization reading and writing, manual coding is not needed, the development efficiency is improved, manual copying and pasting are not needed, the defect is avoided, the packaging serialization packaging device is converted, the quantity of engineering codes and the quantity of functions are reduced, and the space is reduced.
Drawings
Fig. 1 is a schematic diagram of an internal structure of a terminal in one embodiment;
FIG. 2 is a diagram illustrating an internal architecture of a backend server in one embodiment;
FIG. 3 is a flow diagram of a method for implementing target serialization in one embodiment;
FIG. 4 is a flow diagram of a method for class serialization implementation in one embodiment;
FIG. 5 is a flow diagram of a method for implementing database serialization in one embodiment;
FIG. 6 is a block diagram showing an example of an apparatus for realizing object serialization;
FIG. 7 is a block diagram showing the structure of an apparatus for realizing object serialization in another embodiment;
FIG. 8 is a block diagram showing the structure of an apparatus for realizing object serialization in another embodiment;
FIG. 9 is a block diagram showing the structure of an apparatus for realizing object serialization in another embodiment;
FIG. 10 is a block diagram showing the structure of an apparatus for realizing object serialization in another embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
It will be understood that, as used herein, the terms "first," "second," and the like may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another. For example, a first client may be referred to as a second client, and similarly, a second client may be referred to as a first client, without departing from the scope of the present invention. Both the first client and the second client are clients, but they are not the same client.
Fig. 1 is a schematic diagram of an internal structure of a terminal in one embodiment. As shown in fig. 1, the terminal includes a processor, a storage medium, a memory, a network interface, a display screen, a speaker, and an input device, which are connected through a system bus. The storage medium of the terminal stores an operating system and also comprises a target serialization realizing device, and the target serialization realizing device is used for realizing a target serialization realizing method. The processor is used for providing calculation and control capability and supporting the operation of the whole terminal. The memory in the terminal provides an environment for the operation of the target serialization realization device in the storage medium, and the network interface is used for performing network communication with the server, such as sending a data request to the server and receiving data returned by the server. Wherein the target may comprise a class and/or a database, etc. Classes may be all classes in a Java class that need to be serialized. The display screen of the terminal can be a liquid crystal display screen or an electronic ink display screen, and the input device can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on a shell of the terminal, or an external keyboard, a touch pad or a mouse. The terminal may be a mobile phone, a tablet computer or a personal digital assistant. Those skilled in the art will appreciate that the configuration shown in fig. 1 is a block diagram of only a portion of the configuration relevant to the present application, and does not constitute a limitation on the terminal to which the present application is applied, and that a particular terminal may include more or less components than those shown in the drawings, or may combine certain components, or have a different arrangement of components.
Fig. 2 is a schematic diagram of an internal structure of the backend server in one embodiment. As shown in fig. 2, the background server includes a processor, a storage medium, a memory, and a network interface connected via a system bus. The storage medium of the server stores an operating system, a database and a target serialization realizing device, the database stores target serialization data, and the target serialization realizing device is used for realizing a target serialization realizing method suitable for the server. The processor of the server is used for providing calculation and control capacity and supporting the operation of the whole server. The memory of the server provides an environment for the operation of the target serialization realization device in the storage medium. The network interface of the server is used for communicating with an external terminal through a network connection, such as receiving a data request sent by the terminal and returning data to the terminal. The server may be implemented as a stand-alone server or as a server cluster consisting of a plurality of servers. Those skilled in the art will appreciate that the architecture shown in fig. 2 is a block diagram of only a portion of the architecture associated with the subject application, and does not constitute a limitation on the servers to which the subject application applies, as a particular server may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
FIG. 3 is a flow diagram of a method for implementing target serialization in one embodiment. As shown in fig. 3, a target serialization implementation method includes the following steps:
step 302, automatically acquiring a portion to be serialized in the target.
Specifically, the part to be serialized in the acquisition target can be acquired by a character string matching manner or an annotation tag is added, and query is performed to the acquisition of the annotation tag, but the method is not limited to this.
In one embodiment, step 302 includes: and searching the members matched with the preset character strings from the target, and taking the matched members as the parts to be serialized.
Specifically, the predetermined character string may be set as needed, such as% #, &%, # and the like, without being limited thereto.
And if the target comprises the class, searching a member matched with the first preset character string from the class, and taking the matched member as a part to be serialized in the class.
The first predetermined string may be set according to the requirement, such as% #, &%, & and the like, but is not limited thereto.
And if the target comprises a database, searching the member matched with the second preset character string from the database, and taking the matched member as a part to be serialized in the class.
The second predetermined string may be set according to the requirement, such as% #, &%, & and the like, but is not limited thereto. And the first predetermined string is different from the second predetermined string. The part needing serialization can be quickly found through character string matching without additionally adding marks.
And 304, analyzing the part to be serialized in the target to obtain an analysis result, and storing the analysis result.
Specifically, the target may include one or both of a class and a database, etc. If the target comprises the class, the analysis result comprises class information, mainly type information of class members and the like. If the target comprises a database, the analysis result comprises data table information in the database and the like. And storing the analysis result in a memory cache for subsequent calling.
Step 306, serializing the target according to the analysis result, and converting the target into a packaging serialization wrapper.
Specifically, the target is converted to the ParcelWrapper class, i.e., the packing serialization wrapper, wraps the automatically serialized portion. Basic types supported by the conversion include String (type of character String), smartpark (type of automatic serialization), park (type of Android system), ArrayList (type of array list), Map (data structure), and the like.
Step 308, the packaging serialization wrapper is called, and the target is serialized read and written through a reflection mechanism.
Specifically, calling ParcelWrapper, and performing serialized reading and writing on the target through a reflection mechanism according to the analysis result. The reflection mechanism is a capability provided by the Java system. The reflection mechanism refers to that in a running state of the Java, all attributes and methods of any class can be known, any method and attribute of any object can be called, and the dynamically acquired information and the function of dynamically calling the method of the object are called as the reflection mechanism of the Java language.
The Java reflection mechanism mainly provides the following functions: judging the class to which any one object belongs at the time of running; constructing an object of any one class at runtime; judging member variables and methods of any one class during running; calling a method of any one object at runtime; a dynamic proxy is generated.
According to the target serialization realization method, the part to be serialized in the target is automatically acquired, the analysis result is obtained through analysis, the target is serialized according to the analysis result and is converted into the packaging serialization packaging device, the packaging serialization packaging device and the reflection mechanism are called to perform serialization reading and writing, manual coding is not needed, the development efficiency is improved, manual copying and pasting are not needed, the defect is avoided, the packaging serialization packaging device is converted, the quantity of engineering codes and the quantity of functions are reduced, and the space is reduced.
In an embodiment, the target serialization realization method further includes: annotation tags are added to the members of the target to be serialized. Annotation tags may be predefined tags that represent members of the target that require serialization. When a plurality of targets are provided, the annotation tag adopted by each target is different, and each target corresponds to the annotation tag.
The automatically acquiring the portion to be serialized in the target includes: and acquiring a part of the target recorded with the annotation mark as a part to be serialized in the target. By adding the annotation mark, the corresponding part to be serialized can be conveniently and quickly found, and codes and functions do not need to be repeatedly written, so that the data volume is reduced.
FIG. 4 is a flow diagram that illustrates a methodology for class serialization in one embodiment. As shown in fig. 4, the object is a class, and a class serialization implementation method includes the following steps:
at step 402, a first annotation tag is added to a member to be serialized in a class.
Specifically, the first annotation mark is set as needed, such as @ needleparcel or @ n or # m, but is not limited thereto.
For example, the code in the class with the annotation tag added is as follows:
Figure BDA0000837072190000061
Figure BDA0000837072190000071
the addition of the first annotation tag @ needleparcel to the members of the class, described above, indicates that serialization is required.
Step 404, acquiring a part of the class recorded with the first annotation mark as a part to be serialized in the class.
Specifically, the portion having the first annotation tag is identified as the portion of the class to be serialized.
And 406, analyzing the part to be serialized in the class to obtain an analysis result, and storing the analysis result.
Specifically, the analysis result includes class information, mainly type information of class members, and the like.
And step 408, serializing the class according to the analysis result, and converting the class into a packaging serialization wrapper.
Specifically, converting a class to a ParcelWrapper class, i.e., a pack serialization wrapper, wraps the automatically serialized portion. Basic types supported by the conversion include String (type of character String), smartpark (type of automatic serialization), park (type of Android system), ArrayList (type of array list), Map (data structure), and the like.
The SmartParacelable interface is an interface of a serialized class, any function is not required to be realized, and a member for realizing serialization in the class can be acquired through the SmartParacelable interface.
Step 410, the packaging serialization wrapper is called, and serialization reading and writing are carried out on the type through a reflection mechanism.
Specifically, calling ParcelWrapper, and performing serialized reading and writing on the target through a reflection mechanism according to the analysis result.
According to the class serialization realization method, the first annotation mark is added to the member to be serialized in the class, the part to be serialized in the class is obtained according to the first annotation mark, the analysis result is obtained through analysis, the class is serialized according to the analysis result and is converted into the packaging serialization packaging machine, the packaging serialization packaging machine and a reflection mechanism are called to perform serialization reading and writing, manual coding is not needed, the development efficiency is improved, manual copying and pasting are not needed, the defect is avoided, the packaging serialization packaging machine is converted, the quantity of engineering codes and the quantity of functions are reduced, and the space is reduced.
FIG. 5 is a flow diagram that illustrates a methodology for database serialization in one embodiment. As shown in fig. 5, the target is a database, and a method for implementing database serialization includes the following steps:
step 502, adding a second annotation tag to the member to be serialized in the database.
Specifically, the second annotation mark is set as needed, such as @ DbValue or @ t or # p, but not limited thereto. When there are multiple targets, the annotation tag used by each target is different.
For example, in the original DbcacheData interface, the following four functions need to be manually implemented:
*Interface that must be implemented and provided as a public CREATOR
*field that provides some static access of your cache data.
@Public
public static interface DbCreator<T extends DbCacheable>{
@public
public Structure[]structure();
@public
public String[]sortorder();
@public
public T createFromCursor(Cursor cursor);
@public
public int version();
}
the addition of the second annotation tag @ DbValue descendant is as follows:
Class that help Auto write or read the Dbdata;
Version control of this data,define a static int field named VERSION_INT,like;
private static final INT VERSION _ INT 8; // database version number
Sort order of this data,define a static String filed named ORDER_STR,like;
Simple example:
Public class AppInfo extends AutoDbData{
Private static final INT VERSION _ INT 8; // database version number
//@DbValue(true)means this Colum should be UNIQUE
//default is false;
@DbValue(true)
public int appid;
@DbValue(true)
public String appname;
@DbValue(true)
public String iconUrl;
@DbValue(true)
public String downloadUrl;
@DbValue(true)
public String summary;
@DbValue(true)
public int isRecommend;
@DbValue(true)
public String packageName;
@DbValue(true)
public String h5_ url; // touch screen application Address
@DbValue(true)
public String record comment; // details of recommendations
@DbValue(true)
public int maskAppType;
// local
Public int appType=AppType.OTHER_APPLICATION;
Public long installTime=0;
Public int cancelable=0;
Public AppInfo(){
}
Additionally, the annotation tag may also be set to true, indicating uniqueness in the data table.
Step 504, the part of the database recorded with the second annotation mark is obtained as the part to be serialized in the class.
In particular, the portion having the second annotation tag is identified as the portion of the class to be serialized.
Step 506, analyzing the part to be serialized in the database to obtain an analysis result, and storing the analysis result.
Specifically, the analysis result includes data table information in the database, and the like.
And step 508, serializing the database according to the analysis result, and converting the database into a packaging serialization wrapper.
Specifically, the database is converted to a ParcelWrapper class, i.e., a pack serialization wrapper, wraps the automatically serialized portion. Basic types supported by the conversion include String (type of character String), smartpark (type of automatic serialization), park (type of Android system), ArrayList (type of array list), Map (data structure), and the like.
The SmartParacelable interface is an interface of a serialized class, any function is not required to be realized, and a member for realizing serialization in the class can be acquired through the SmartParacelable interface.
Step 510, the packing serialization wrapper is called, and the database is serialized read and written through a reflection mechanism.
Specifically, calling ParcelWrapper, and performing serialized reading and writing on the database through a reflection mechanism according to the analysis result.
According to the method for realizing database serialization, the second annotation mark is added to the member to be serialized in the database, the part to be serialized in the database is obtained according to the second annotation mark, the analysis result is obtained through analysis, the database is serialized according to the analysis result and is converted into the packaging serialization packaging machine, the packaging serialization packaging machine and a reflection mechanism are called for serialization reading and writing, manual coding is not needed, the development efficiency is improved, manual copying and pasting are not needed, the defect is avoided, the packaging serialization packaging machine is converted, the quantity of engineering codes and the quantity of functions are reduced, and the space is reduced.
In an embodiment, the method for implementing database serialization further includes: and storing the version number of the data table in the database, and setting the static value of the version number of the data table.
Specifically, the data table VERSION number writes static final INT VERSION _ INT ═ 8; and setting a static value of the version number of the data packet, and automatically increasing the version number by 1 each time the version number is updated.
Further, in the method for implementing database serialization, the method further includes: and sorting the data table and setting a static value of a sorting mode.
Specifically, by writing "static final String ORDER _ STR ═ columns.fed _ PRIORITY +" DESC, "+ columns.publish _ DATE +" DESC "; and setting a sorting mode according to the static value of the' step, and sorting according to the sorting mode. By setting the static value, no function needs to be generated, and information can be read through reflection. And automatically sequencing the data tables in the database according to the needs.
In other embodiments, the target serialization implementation method may serialize the class and the database at the same time, and if the annotation tag is used, the first annotation tag added by the member in the class is different from the second annotation tag added by the member in the database, so as to distinguish the two annotation tags.
The target serialization realization method is applied to the space of the instant communication application program, about 200 classes can be reduced, and 900 functions can be reduced. And in the development, the serialized classes do not need to be written manually, so that the development efficiency is improved. Operation efficiency: the automatic execution time consumption is divided into two steps, namely class analysis (which analyzed fields need to be read and written, field types and the like) and data reading and writing, the class analysis time consumption is high, the analysis result is cached, and the analysis is performed once only when the analysis result is used for the first time. The total reading and writing time of the general data class is about 2 ms. In addition, the manual writing is supported for the classes with higher reading and writing density or more times, and the execution efficiency is improved. Intermediate objects in the class may use a pool of objects, reducing the occurrence of fragmented objects.
FIG. 6 is a block diagram showing an apparatus for implementing object serialization in one embodiment. As shown in fig. 6, an apparatus for implementing target serialization includes an obtaining module 610, a parsing module 620, a converting module 630, and a calling module 640. Wherein:
the obtaining module 610 is configured to automatically obtain a portion of the target to be serialized.
Specifically, the obtaining module 610 obtains the portion to be serialized in the target by obtaining or adding the annotation tag in a character string matching manner, and querying to obtain the annotation tag.
In one embodiment, the obtaining module 610 is further configured to find a member matching the predetermined character string from the target, and treat the matching member as the portion to be serialized.
Specifically, the predetermined character string may be set as needed, such as% #, &%, # and the like, without being limited thereto.
If the target includes a class, the obtaining module 610 searches a member matched with the first predetermined character string from the class, and takes the matched member as a part to be serialized in the class.
The first predetermined string may be set according to the requirement, such as% #, &%, & and the like, but is not limited thereto.
If the target includes a database, the obtaining module 610 searches a member matched with the second predetermined character string from the database, and takes the matched member as a part to be serialized in the class.
The second predetermined string may be set according to the requirement, such as% #, &%, & and the like, but is not limited thereto. And the first predetermined string is different from the second predetermined string. The part needing serialization can be quickly found through character string matching without additionally adding marks.
The parsing module 620 is configured to parse the portion to be serialized in the target to obtain a parsing result, and store the parsing result.
Specifically, the target may include one or both of a class and a database, etc. If the target comprises the class, the analysis result comprises class information, mainly type information of class members and the like. If the target comprises a database, the analysis result comprises data table information in the database and the like. And storing the analysis result in a memory cache for subsequent calling.
The converting module 630 is configured to serialize the class according to the parsing result, and convert the class into a packing serialization wrapper.
Specifically, the target is converted to the ParcelWrapper class, i.e., the packing serialization wrapper, wraps the automatically serialized portion. Basic types supported by the conversion include String (type of character String), smartpark (type of automatic serialization), park (type of Android system), ArrayList (type of array list), Map (data structure), and the like.
The calling module 640 is configured to call the packing serialization wrapper, and perform serialization reading and writing on the class through a reflection mechanism.
Specifically, calling ParcelWrapper, and performing serialized reading and writing on the target through a reflection mechanism according to the analysis result. The reflection mechanism is a capability provided by the Java system.
The target serialization realization device obtains the part to be serialized in the target automatically, analyzes the part to obtain an analysis result, serializes the target according to the analysis result, converts the part to be serialized into the packaging serialization packaging device, and performs serialization reading and writing by calling the packaging serialization packaging device and a reflection mechanism without manual coding, so that the development efficiency is improved, manual copying and pasting are not needed, the defect is avoided, the part is converted into the packaging serialization packaging device, the quantity of engineering codes and the quantity of functions are reduced, and the space is reduced.
FIG. 7 is a block diagram showing the structure of an apparatus for realizing object serialization in another embodiment. As shown in fig. 7, an apparatus for implementing target serialization includes a labeling module 650 in addition to an obtaining module 610, a parsing module 620, a converting module 630 and a calling module 640. Wherein:
the annotation module 650 is used to add annotation tags to the members of the target to be serialized.
Annotation tags may be predefined tags that represent members of the target that require serialization. When a plurality of targets are provided, the annotation tag adopted by each target is different, and each target corresponds to the annotation tag.
The obtaining module 610 is further configured to obtain a portion of the target recorded with the annotation mark as a portion of the target to be serialized. By adding the annotation mark, the corresponding part to be serialized can be conveniently and quickly found, and codes and functions do not need to be repeatedly written, so that the data volume is reduced.
FIG. 8 is a block diagram showing the structure of an apparatus for realizing object serialization in another embodiment. As shown in fig. 8, the object includes a class, and an object serialization implementation apparatus includes a first marking module 660 in addition to an obtaining module 610, a parsing module 620, a converting module 630 and a calling module 640. Wherein:
the first annotation module 660 is configured to add a first annotation tag to the member of the class to be serialized.
Specifically, the first annotation mark is set as needed, such as @ needleparcel or @ n or # m, but is not limited thereto.
The obtaining module 610 is further configured to obtain a portion of the class in which the first annotation mark is recorded as a portion to be serialized in the class.
The parsing module 620 is further configured to parse the portion to be serialized in the class to obtain a parsing result, and store the parsing result. Specifically, the analysis result includes class information, mainly type information of class members, and the like.
The converting module 630 is further configured to serialize the class according to the parsing result, and convert the class into a packing serialization wrapper. The SmartParacelable interface is an interface of a serialized class, any function is not required to be realized, and a member for realizing serialization in the class can be acquired through the SmartParacelable interface.
The calling module 640 is further configured to call the packing serialization wrapper to perform serialization reading and writing on the class through a reflection mechanism.
Specifically, calling ParcelWrapper, and performing serialized reading and writing on the target through a reflection mechanism according to the analysis result.
The class serialization realization device obtains the part to be serialized in the class according to the first annotation mark by adding the first annotation mark to the member to be serialized in the class, analyzes the part to be serialized to obtain an analysis result, serializes the class according to the analysis result, converts the class into the packaging serialization packaging device, and carries out serialization reading and writing by calling the packaging serialization packaging device and a reflection mechanism without manual coding, thereby improving the development efficiency, avoiding the manual copying and pasting, avoiding the introduction of defects, converting the class serialization packaging device into the packaging serialization packaging device, reducing the quantity of engineering codes and the quantity of functions, and reducing the space.
FIG. 9 is a block diagram showing the structure of an apparatus for realizing object serialization in another embodiment. As shown in fig. 9, the object includes a database, and an object serialization implementation apparatus includes a second marking module 670 in addition to the obtaining module 610, the parsing module 620, the converting module 630 and the calling module 640. Wherein:
the second annotation module 670 is for adding a second annotation tag to the database member.
Specifically, the second annotation mark is set as needed, such as @ DbValue or @ t or # p, but not limited thereto. When there are multiple targets, the annotation tag used by each target is different.
The obtaining module 610 is further configured to obtain a portion of the database where the second annotation mark is recorded as a portion to be serialized in the database.
The parsing module 620 is further configured to parse the portion to be serialized in the database to obtain a parsing result, and store the parsing result. Specifically, the analysis result includes data table information in the database, and the like.
The conversion module 630 is further configured to serialize the database according to the parsing result, and convert the database into a packing serialization wrapper.
The calling module 640 is further configured to call the packing serialization wrapper to perform serialization reading and writing on the database through a reflection mechanism.
Specifically, calling ParcelWrapper, and performing serialized reading and writing on the database through a reflection mechanism according to the analysis result.
According to the device for realizing database serialization, the second annotation mark is added to the member to be serialized in the database, the part to be serialized in the database is obtained according to the second annotation mark, the analysis result is obtained through analysis, the database is serialized according to the analysis result and is converted into the packaging serialization packaging device, the packaging serialization packaging device and a reflection mechanism are called for serialization reading and writing, manual coding is not needed, the development efficiency is improved, manual copying and pasting are not needed, the defect is avoided, the packaging serialization packaging device is converted, the quantity of engineering codes and the quantity of functions are reduced, and the space is reduced.
FIG. 10 is a block diagram showing the structure of an apparatus for realizing object serialization in another embodiment. As shown in fig. 10, the object includes a database, and an object serialization implementation apparatus includes a storage module 680 and an ordering module 690 in addition to the obtaining module 610, the parsing module 620, the converting module 630, the calling module 640, the second marking module 670.
The storage module 680 is configured to store a data table version number in the database, and set a static value of the data table version number.
Specifically, the data table VERSION number writes static final INT VERSION _ INT ═ 8; and setting a static value of the version number of the data packet, and automatically increasing the version number by 1 each time the version number is updated.
The sorting module 690 is configured to sort the data table and set a static value of the sorting manner.
By setting the static value, no function needs to be generated, and information can be read through reflection.
In other embodiments, the target serialization implementation apparatus may include any possible combination of the obtaining module 610, the parsing module 620, the converting module 630, the calling module 640, the first marking module 660, the second marking module 670, the storing module 680, and the sorting module 690, which is not described herein again.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a non-volatile computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the program is executed. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), or the like.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (11)

1. A target serialization realization method comprises the following steps:
when the target comprises a class, adding a first annotation mark to a member to be serialized in the class; when the target comprises a database, adding a second annotation tag to a member of the database; the first annotation tag added by a member in the class is different from the second annotation tag added by a member in the database;
acquiring a part of the class, in which the first annotation mark is recorded, as a part to be serialized in the class; acquiring a part of the database, which records the second annotation mark, as a part to be serialized in the database;
analyzing the part to be serialized in the target to obtain an analysis result, and storing the analysis result; if the target comprises a class, the analysis result comprises class information, and the class information is the type information of class members; if the target comprises a database, the analysis result comprises data table information in the database;
serializing the target according to the analysis result, and converting the target into a packaging serialization wrapper; the packaging serialization packer is a ParcelWrapper class;
calling the packaging serialization packer, and performing serialization reading and writing on the target through a reflection mechanism according to the analysis result;
and when the target comprises a database, reading a static value of a sorting mode of the data tables in the database through a reflection mechanism, so that the data tables in the database are automatically sorted.
2. The method of claim 1, wherein before the parsing the portion of the target to be serialized to obtain a parsing result, the method further comprises:
and searching the members matched with the preset character strings from the target, and taking the matched members as the parts to be serialized.
3. The method of claim 1, wherein if the target comprises a class, the parsing result comprises class information; and if the target comprises a database, the analysis result comprises the data table information of the database.
4. The method of claim 1, further comprising:
storing a data table version number in the database, and setting a static value of the data table version number;
and sequencing the data table and setting a static value of a sequencing mode.
5. An object serialization realization apparatus, comprising:
the system comprises a first annotation module, a second annotation module and a third annotation module, wherein the first annotation module is used for adding a first annotation mark to a member to be serialized in a class when a target comprises the class;
a second annotation module for adding a second annotation tag to a member of the database when the target comprises the database; the first annotation tag added by a member in the class is different from the second annotation tag added by a member in the database;
the acquisition module is used for acquiring a part of the class, in which the first annotation mark is recorded, as a part to be serialized in the class; acquiring a part of the database, which records the second annotation mark, as a part to be serialized in the database;
the analysis module is used for analyzing the part to be serialized in the target to obtain an analysis result and storing the analysis result; if the target comprises a class, the analysis result comprises class information, and the class information is the type information of class members; if the target comprises a database, the analysis result comprises data table information in the database;
the conversion module is used for serializing the target according to the analysis result and converting the target into a packaging serialization wrapper; the packaging serialization packer is a ParcelWrapper class;
the calling module is used for calling the packaging serialization packer and performing serialization reading and writing on the target through a reflection mechanism according to the analysis result; and when the target comprises a database, reading a static value of a sorting mode of the data tables in the database through a reflection mechanism, so that the data tables in the database are automatically sorted.
6. The apparatus of claim 5, wherein the obtaining module is further configured to find a member matching a predetermined character string from the target, and treat the matching member as the portion to be serialized.
7. The apparatus of claim 5, wherein if the target comprises a class, the parsing result comprises class information; and if the target comprises a database, the analysis result comprises the data table information of the database.
8. The apparatus of claim 5, further comprising:
the storage module is used for storing a data table version number in the database and setting a static value of the data table version number;
and the sorting module is used for sorting the data table and setting a static value of a sorting mode.
9. A terminal comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method according to any one of claims 1 to 4.
10. A server comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method of any one of claims 1 to 4.
11. A computer-readable storage medium, storing a computer program which, when executed by a processor, causes the processor to carry out the steps of the method according to any one of claims 1 to 4.
CN201510735570.XA 2015-11-02 2015-11-02 Target serialization realization method and device Active CN106648569B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510735570.XA CN106648569B (en) 2015-11-02 2015-11-02 Target serialization realization method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510735570.XA CN106648569B (en) 2015-11-02 2015-11-02 Target serialization realization method and device

Publications (2)

Publication Number Publication Date
CN106648569A CN106648569A (en) 2017-05-10
CN106648569B true CN106648569B (en) 2021-04-20

Family

ID=58809842

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510735570.XA Active CN106648569B (en) 2015-11-02 2015-11-02 Target serialization realization method and device

Country Status (1)

Country Link
CN (1) CN106648569B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107450922B (en) * 2017-07-27 2020-01-03 武汉斗鱼网络科技有限公司 Method, storage medium, device and system for automatically registering popup events in android
CN108401008B (en) * 2018-01-12 2021-05-07 深圳壹账通智能科技有限公司 Method and system for synchronous operation of equipment
CN109857742B (en) * 2019-01-18 2021-03-02 烽火通信科技股份有限公司 Big data virtual table rapid display method and system
CN111931200B (en) * 2020-07-13 2024-02-23 车智互联(北京)科技有限公司 Data serialization method, mobile terminal and readable storage medium
CN112130837B (en) * 2020-09-25 2022-03-08 腾讯科技(深圳)有限公司 Code processing method and device and storage medium
CN114331416A (en) * 2021-12-30 2022-04-12 深圳市兆珑科技有限公司 Data processing method and device, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101807168A (en) * 2010-03-15 2010-08-18 北京航空航天大学 Testing environment of digital terminal for supporting edition compatibility and building method thereof
CN101826112A (en) * 2010-05-05 2010-09-08 山东中创软件工程股份有限公司 Method, device and system for storing and reading list data
CN102495757A (en) * 2011-11-15 2012-06-13 深圳市融创天下科技股份有限公司 Optimization method applicable to JAVA remote invocation object transfer and device
CN104360865A (en) * 2014-11-28 2015-02-18 中国建设银行股份有限公司 Serialization method, deserialization method and related equipment
CN104881461A (en) * 2015-05-22 2015-09-02 国云科技股份有限公司 Rapid data storage method

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
ES2204144T3 (en) * 1998-02-20 2004-04-16 Thomson Licensing S.A. A SYSTEM TO FORM, SEGMENT AND TREAT OBJECTS OF ELECTRONIC PROGRAM GUIDES.
US7451432B2 (en) * 2004-10-01 2008-11-11 Microsoft Corporation Transformation of componentized and extensible workflow to a declarative format
CN100517224C (en) * 2007-06-13 2009-07-22 北京北大方正电子有限公司 Serializing storage of objects and recovering system and method thereof
CN102523128B (en) * 2011-12-31 2014-09-24 浙江万朋网络技术有限公司 Data synchronism method in remote data transmission
CN103488519B (en) * 2013-09-27 2016-05-25 上海野火网络科技有限公司 A kind of implementation method of interactive script language interpreter
JP6211949B2 (en) * 2014-02-12 2017-10-11 株式会社東芝 Database device
CN103902698B (en) * 2014-03-31 2018-04-13 北京皮尔布莱尼软件有限公司 A kind of data-storage system and storage method
CN104486396B (en) * 2014-12-10 2017-12-26 中国电信集团系统集成有限责任公司 A kind of transmission method of cross-platform network data
CN104731654B (en) * 2015-04-03 2018-03-27 南京大学 A kind of migration reconstruct and support system for Android application
CN104883292B (en) * 2015-04-16 2017-03-22 江苏中威科技软件系统有限公司 Method and system for realizing message roaming at different terminals

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101807168A (en) * 2010-03-15 2010-08-18 北京航空航天大学 Testing environment of digital terminal for supporting edition compatibility and building method thereof
CN101826112A (en) * 2010-05-05 2010-09-08 山东中创软件工程股份有限公司 Method, device and system for storing and reading list data
CN102495757A (en) * 2011-11-15 2012-06-13 深圳市融创天下科技股份有限公司 Optimization method applicable to JAVA remote invocation object transfer and device
CN104360865A (en) * 2014-11-28 2015-02-18 中国建设银行股份有限公司 Serialization method, deserialization method and related equipment
CN104881461A (en) * 2015-05-22 2015-09-02 国云科技股份有限公司 Rapid data storage method

Also Published As

Publication number Publication date
CN106648569A (en) 2017-05-10

Similar Documents

Publication Publication Date Title
CN106648569B (en) Target serialization realization method and device
US9558214B1 (en) Secondary mappings to enable code changes without schema updates
WO2019085474A1 (en) Calculation engine implementing method, electronic device, and storage medium
US20070226273A1 (en) Updating a local version of a file based on a rule
CN113204345A (en) Page generation method and device, electronic equipment and storage medium
CN110365776B (en) Picture batch downloading method and device, electronic equipment and storage medium
CN107408055B (en) Code cache system
CN110888972A (en) Sensitive content identification method and device based on Spark Streaming
CN106502707B (en) Code generation method and device
CN113760894A (en) Data calling method and device, electronic equipment and storage medium
US20110099166A1 (en) Extending types hosted in database to other platforms
CN113127776A (en) Breadcrumb path generation method and device and terminal equipment
CN110795920A (en) Document generation method and device
US8578268B2 (en) Rendering electronic documents having linked textboxes
US20170364496A1 (en) Visualization interface for information object system
CN114969044A (en) Materialized column creating method based on data lake and data query method
US10908924B2 (en) System and methods for loading objects from hash chains
CN115905274A (en) Data processing method and device, electronic equipment and medium
JP6870454B2 (en) Analytical equipment, analytical programs and analytical methods
CN112347794A (en) Data translation method, device, equipment and computer storage medium
CN111400623A (en) Method and apparatus for searching information
US20180373688A1 (en) Sharing annotations to web pages
CN110134691B (en) Data verification method, device, equipment and medium
CN113032695B (en) Method, apparatus, device and storage medium for replacing data source
US20230334069A1 (en) Cross-platform content management

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
GR01 Patent grant
GR01 Patent grant