Method and device for converting object into Map, computer equipment and medium

By constructing object entity classes and object conversion processing classes, and using the reflection mechanism to convert complex objects into Maps, it solves the problem that existing tools are difficult to process nested entity classes and List objects, achieves efficient and low-cost object conversion, and improves efficiency. Software development efficiency and accuracy.

CN118535159APending Publication Date: 2024-08-23PING AN PAY ELECTRONIC PAYMENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410725273.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-05
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

Existing object conversion tools are difficult to handle complex nested entity classes and List objects, and have high code duplication rates and difficult maintenance. They cannot effectively convert nested entity classes in entity classes and objects containing List objects.

Method used

By constructing object entity classes and object conversion processing classes, multiple entity attributes and conversion rules of objects are defined, and the reflection mechanism is used to convert entity objects into Map form, providing a unified conversion tool to support the conversion of complex objects.

Benefits of technology

It significantly reduces the labor and code maintenance costs of converting objects into Maps, improves the efficiency of software engineering development, provides high scalability and high conversion accuracy, and reduces the risks of software project development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535159A
    Figure CN118535159A
Patent Text Reader

Abstract

The invention relates to a method and device for converting an object into Map, computer equipment and a medium. The method comprises the steps that an object entity class of a pre-constructed object conversion operation tool class is called, a received to-be-converted object is extracted as an entity object, and multiple entity attributes of the object are defined in the object entity class; an object conversion processing class of the object conversion operation tool class is called, the entity object is converted into a Map form based on a reflection mechanism according to configuration information of the object conversion operation tool class, and the configuration information is configured at least according to an object conversion rule preset in the object conversion processing class. According to the method, the labor cost and the code maintenance cost for converting the object into the Map are reduced, and the efficiency of software engineering development is remarkably improved; the expansibility of the conversion tool is extremely high, the object entity class and the object conversion processing class can be defined according to actual business requirements, and the real-time performance and the practicability are high; and the conversion accuracy is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the fields of computer technology and finance, and in particular to a method, apparatus, computer equipment and medium for converting an object into a Map. Background Art

[0002] In the process of software development, developers often need to convert an object into a Map. For example, when developing some financial tool software, they often need to convert a user object into a Map. Because of this need, many open source toolkits have gradually encapsulated various conversion tools, but these tools have many shortcomings. For example, existing tools cannot convert entity classes that are nested in entity classes, or convert objects that contain List objects; and the code duplication rate is high, which makes maintenance difficult, time-consuming and labor-intensive. Summary of the invention

[0003] To solve the above problems, embodiments of the present application provide a method, apparatus, computer device, and medium for converting an object into a Map.

[0004] In a first aspect, an embodiment of the present application provides a method for converting an object into a Map, including:

[0005] Calling the object entity class of the pre-built object conversion operation tool class, extracting the received object to be converted as an entity object, wherein a plurality of entity attributes of the object are defined in the object entity class;

[0006] The object conversion processing class of the object conversion operation tool class is called, and according to the configuration information of the object conversion operation tool class, the entity object is converted into a Map form based on the reflection mechanism, wherein the configuration information is configured at least according to the object conversion rules preset in the object conversion processing class.

[0007] In a second aspect, an embodiment of the present application further provides a device for converting an object into a Map, wherein the device for converting an object into a Map comprises:

[0008] A first calling unit is used to call an object entity class of a pre-built object conversion operation tool class to extract the received object to be converted as an entity object, wherein a plurality of entity attributes of the object are defined in the object entity class;

[0009] The second calling unit is used to call the object conversion processing class of the object conversion operation tool class, and convert the entity object into a Map form based on the reflection mechanism according to the configuration information of the object conversion operation tool class, wherein the configuration information is configured at least according to the object conversion rules preset in the object conversion processing class.

[0010] In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, any of the above-mentioned methods for converting an object into a Map is implemented.

[0011] In a fourth aspect, a computer-readable storage medium is provided, which stores a computer program, and when the computer program is instructed by a processor, it implements the method of converting any of the above objects into a Map.

[0012] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:

[0013] The present application provides a method for converting an object into a Map, and provides a tool for converting a complex object into a Map object. Specifically, an object entity class is constructed, and multiple entity attributes of an object to be converted are defined in the object entity class; then an object conversion processing class is constructed, and conversion rules for converting the object to be converted into a Map are defined in the object conversion processing class; then the object entity class and the object conversion processing class are integrated into an object conversion operation tool class. When converting an object, the object is used as an input parameter, and first, based on the object entity class, an entity object consisting of multiple entity attributes and entity attribute values ​​defined in the object entity class is extracted from the received object, and then, based on the object conversion processing class, one or more attributes of the entity object are converted according to the object conversion rules defined in the object conversion processing class to obtain the Map form of the object to be converted and return it. This application first converts the object to be converted into a predefined entity object containing multiple entity attributes, and then converts the entity object into a Map form according to a preset conversion rule, thereby providing a unified conversion tool to the outside world, significantly reducing the labor cost and code maintenance cost of converting the object into a Map, and significantly improving the efficiency of software engineering development; the conversion tool is highly scalable, and both the object entity class and the object conversion processing class can be defined according to actual business needs, and during the application process, they can also be modified at any time according to business needs, supporting immediate use, and having strong real-time and practicality; and the conversion accuracy is high, which significantly reduces the risk of software project development. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0015] Figure 1 A schematic diagram showing a flow chart of a method for converting an object into a Map according to an embodiment of the present application;

[0016] Figure 2A schematic diagram of a process of converting an entity object into a Map by a conversion object processing class according to an embodiment of the present application is shown;

[0017] Figure 3 A device for converting an object into a Map according to an embodiment of the present application is shown;

[0018] Figure 4 A schematic diagram showing the structure of a computer device according to an embodiment of the present application is shown;

[0019] Figure 5 A schematic structural diagram of a computer device according to another embodiment of the present application is shown. DETAILED DESCRIPTION

[0020] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.

[0021] With the rapid development of computer technology, financial software tools are playing an increasingly significant role in people's lives. For example, financial software systems can be insurance systems, banking systems, trading systems, order systems, etc. These systems support functions such as applying for loans, credit cards, or purchasing insurance and financial products, making people's lives more convenient.

[0022] Currently in the software development process, development engineers often need to convert an object into a Map. For example, financial software tools usually need to support the management of user information. During development, a user object needs to be converted into a Map.

[0023] Because of this demand, many open source toolkits have gradually encapsulated various conversion operation tool classes. However, in fact, these tools are not easy to use. Most of them are designed for converting simple entity classes to Maps, and most of them have the following two problems:

[0024] First, it is not possible to convert entity classes that are nested within entity classes or objects that contain List objects. For example, a user (Person) object contains a wallet (Wallet) object, and the wallet contains a bank card (BankCard) object, which may be a collection, that is, there may be multiple bank cards in the wallet. This is a typical complex nested entity class. Existing tools have poor conversion effects or are not applicable to such complex objects.

[0025] Second, because existing tools usually do not have a rendering method and the code duplication rate is high, code maintenance is difficult, time-consuming and laborious. For example, if the traditional conversion method is used, you must first create a Map object and then move the attributes of the entity object one by one. If there are multiple places with the same logic, you have to copy a lot of code. If you convert and render the fields, whether you do it at the code level or the page level, you have to write it again in the respective code logic or page, which is very labor-intensive. In this regard, this application provides a method for converting an object to a Map, please refer to Figure 1 , Figure 1 A flow chart of a method for converting an object into a Map according to an embodiment of the present application is shown. Figure 1 It can be seen that the present application at least includes steps S110 to S120:

[0026] Step S110: calling the object entity class of the pre-built object conversion operation tool class, extracting the received object to be converted into an entity object, wherein a plurality of entity attributes of the object are defined in the object entity class.

[0027] The method of converting an object into a Map in this application is implemented by relying on an object conversion operation tool class, which is constructed in advance. Specifically, it includes constructing an object entity class and an object conversion processing class, and defining the flow of the two for processing data.

[0028] Specifically, in some embodiments of the present application, the object conversion operation tool class is integrated according to the following method: in the operation tool class development file package, the object conversion operation tool class is established; in the object conversion operation tool class, the object entity class is defined, the object entity class contains multiple entity attributes of the object, so that the object entity class reads the value of each field in the object to be converted, and the correspondence between each field and each entity attribute defined in the object entity class is written into the object entity class to obtain the entity object; in the object conversion operation tool class, the object conversion processing class is defined, and the object conversion rules pre-set in the object conversion processing class enable the object conversion processing class to obtain the source data of each attribute in the entity object obtained by the object entity class based on the reflection mechanism; the object conversion rules provided by the object conversion processing class are built into the object conversion operation tool class as configuration information, and the object conversion processing class is defined to convert the entity object into Map form according to the configuration information.

[0029] First, an object entity class is constructed, in which a plurality of entity attributes of the object are defined.

[0030] Map can be simply understood as a data container, in which data is stored in the form of key-value pairs. This application is applicable to converting various objects in software project development using various computer languages ​​into Map form. This application is particularly applicable to nested entity classes and List objects.

[0031] For example, a user (Person) object in a financial software system contains a wallet (Wallet) object, and the wallet contains a bank card (BankCard) object, which may be a collection, that is, there may be multiple bank cards in the wallet. This is a typical complex nested entity class. When facing such complex objects, the existing tools have poor conversion effects or are not applicable. In this application, for the convenience of description, an object is taken as an example for explanation, but the object to be converted is not limited to user objects, but can be objects of various subjects, such as enterprise information objects, etc.

[0032] It should be noted that the object to be converted is usually not the Map object itself, because converting a Map object will still result in a Map object, which is meaningless; and the object to be converted is usually not a pure numeric object, such as a string of characters 124ANJGJOS366.

[0033] First, an object entity class is constructed according to business requirements. In some embodiments of the present application, for a user object, multiple entity attributes of the user object are defined in the object entity class, such as but not limited to: user name, mobile phone number, last login date, gender, password, bank card, and creation time, etc.

[0034] For multiple entity attributes in an object entity class, they are defined according to business needs. It can be understood that when processing a business request, the field value under the field consistent with the entity attribute in the object to be converted is required, and in the subsequent conversion process of this application, information will be extracted from the object to be converted according to the multiple attributes defined here to form an entity object.

[0035] Then, an object conversion processing class is constructed, and an object conversion rule of the object is defined in the object conversion processing class.

[0036] In the object conversion processing class (Handle), it is defined how to convert an object into a Map. Specifically, a conversion rule for converting an object into a Map is defined, which is recorded as the object conversion rule here.

[0037] In some embodiments, at least one of a renderer, an exclusion attribute set, an inclusion attribute set, an attribute alias set, and a date specification format, etc. is defined in the object conversion rule of the object conversion processing class; wherein a unified external data format is defined in the renderer; at least one attribute that does not need to be converted is defined in the exclusion attribute set; multiple attributes that need to be converted are defined in the inclusion attribute set; a mapping relationship between the internal name and the external name of at least one attribute is defined in the attribute alias set; and a specified format for displaying time is defined in the date specification format.

[0038] The purpose of defining a renderer is to unify external packaging, that is, to provide a unified external data format. For example, if cardType=01, the returned value is "savings card" in Chinese; cardType=02, the returned value is "credit card" in Chinese; cardType=03, the returned value is "social security card" in Chinese; for example, the middle digits of a mobile phone number may be masked, and the front and back may be displayed normally; for a bank card number, the middle digits may be masked, and the front and back may be displayed normally. These can be defined as needed.

[0039] The purpose of defining an exclusion attribute set is to protect some attributes from being exposed. For example, if an object contains a password, which is sensitive information, it should not be exposed. You can put the "password" attribute into the exclusion attribute set. When converting the object to a Map, determine whether an attribute belongs to the exclusion attribute set. If so, ignore the attribute directly and then convert the next attribute.

[0040] The purpose of defining the included attribute set is to determine which fields need to be displayed. Among all the fields of an object, you can define the included attribute set to include all the attributes you want to display. If an attribute of an object belongs to the included attribute set, the attribute is converted and returned to the Map. There may be an attribute that does not belong to the excluded attribute set or the included attribute set. For such an attribute, it is ignored and the next attribute is converted.

[0041] The purpose of defining an attribute alias set is to establish a mapping relationship between internal and external attributes. For example, the internal name of the attribute gender is called gender, but the external name may need to be displayed as sex. In this case, the attribute gender can be put into the attribute alias set, and a mapping relationship between it and the external name sex can be established. When converting an object to a Map, if an attribute of the object to be converted belongs to the attribute alias set, the external name of the attribute is queried in the attribute alias set and returned to the Map.

[0042] The purpose of defining a date format is to format the date and return the displayed time in the specified format. When displaying the page, different formats may be displayed according to the actual product requirements.

[0043] Finally, the object entity class and the object conversion processing class are integrated into an object conversion operation tool class, so as to extract the received object to be converted as an entity object based on the object entity class; and convert the entity object into a Map form based on the object conversion processing class.

[0044] Finally, the object entity class and the object conversion processing class are integrated into one tool, which is recorded as the object conversion tool. It can be simply understood as establishing an object conversion operation tool class (OprUtil) in which the object entity class and the object processing conversion class are encapsulated. In some embodiments, the object conversion operation tool class can be but not limited to being formed based on the Java language, and can be deployed in the target project in the form of a plug-in, and can be called at any time when the software project is being developed. When the object to be converted is converted, the source data of the object to be converted is used as an input parameter, and the corresponding object entity class and object conversion processing class are called according to the type of the object to be converted. For example, for a user object, the object entity class and the corresponding object conversion processing class of the user object set in advance are called; if it is for an enterprise object, the object entity class and the corresponding object conversion processing class of the enterprise object set in advance are called.

[0045] Specifically, when the tool class is integrated, the object conversion operation tool class is established in the operation tool class development file package, and the object conversion processing class is defined in the object conversion operation tool class to obtain the source data of each attribute in the entity object obtained by the object entity class based on the reflection mechanism; and the object conversion rules provided by the object conversion processing class are built into the object conversion operation tool class as configuration information; the object conversion processing class is defined to convert the entity object into Map form according to the configuration information.

[0046] Specifically, you can first establish a plug-in project, introduce necessary related parameters in the development file of the plug-in project, and then introduce the object entity class. The function of the object entity class is to extract the object to be converted into an entity object. Usually, the source data in the object to be converted includes multiple fields, and each field has a corresponding field value. For example, a user object includes a field name, and the field value under the name is Zhang San. Some or all fields of an object to be converted have a corresponding relationship or are consistent with some or all entity attributes defined in the object entity class. For example, in the user object, there is a field called name, and in the object entity class defined for the user object, there is an attribute called name, so the two have a corresponding relationship.

[0047] This application is particularly suitable for some complex objects. When converting the object to be converted into an entity object, the value of each field in the object to be converted is read, and according to the corresponding relationship between each field and each entity attribute defined in the object entity class, the value corresponding to each entity attribute is written into the object entity class to obtain the entity object. That is, a certain attribute defined in the object entity class can be traversed. For an attribute, the field corresponding to it is queried in the source data of the object to be converted, and then the field value under the field is pulled over and added to the attribute of the entity object. Similarly, the above operation is performed for each attribute in the object entity class to obtain the entity object. Then, the object conversion processing class is defined in the object conversion operation tool class. Specifically, the logic of the object conversion processing class converting the object to Map is roughly as follows: the source data of each attribute of the object to be converted contained in the entity object is obtained through the object conversion processing class, and then each attribute is converted based on the object conversion rules defined in the object conversion processing class to form a Map and then returned. Therefore, we first define that the conversion processing class can obtain the source data of each attribute in the entity object obtained by the object entity class based on the reflection mechanism; then write the object conversion rules defined by the object conversion processing class into the object conversion operation tool class as the configuration information of the object conversion operation tool class. When converting the object, the object conversion processing class can convert each attribute in the entity object in turn according to the configuration information to obtain the Map form of the object to be converted.

[0048] Specifically, if a renderer, an exclusion attribute set, an inclusion attribute set, an attribute alias set, and a date specification format are defined in an object conversion processing class; the object conversion processing class can be defined to convert the converted object according to the following logic, including: defining the object conversion processing class, constructing a Map, and obtaining each entity attribute and the corresponding attribute value in the entity object based on a reflection mechanism; traversing each entity attribute in the entity object in turn, determining whether an entity attribute belongs to the inclusion attribute set, if the entity attribute does not belong to the inclusion attribute set, ignoring the entity attribute and traversing the next entity attribute; if the entity attribute belongs to the inclusion attribute set, determining whether the entity attribute belongs to the exclusion attribute set, if the entity attribute belongs to the exclusion attribute set, ignoring the entity attribute and traversing the next entity attribute; if the entity attribute does not belong to the exclusion attribute set, determining the Whether the entity attribute belongs to the attribute alias set. If the entity attribute belongs to the attribute alias set, the alias of the entity attribute is returned to the Map, and the next entity attribute is traversed; if the entity attribute does not belong to the attribute alias set, it is determined whether the entity attribute is a date type. If the entity attribute is a date type, a security thread is used to return the attribute value of the entity attribute to the Map in the date specified format. If the entity attribute is not a date type, it is determined whether all entity attributes have been traversed. If all entity attributes have not been traversed, the next entity attribute is traversed; if all entity attributes have been traversed, it is determined whether the rendering class of the entity attribute is empty. If the rendering class of the entity attribute is empty, the next entity attribute is traversed. If the rendering class of the entity attribute is not empty, a Map is returned according to the unified external data format defined in the renderer.

[0049] When converting the object to be converted, the object entity class of the pre-built object conversion operation tool class is called to extract the received object to be converted as an entity object, wherein a plurality of entity attributes of the object are defined in the object entity class.

[0050] In some embodiments of the present application, in the above method, the object entity class of the pre-built object conversion operation tool class is called to extract the received object to be converted as an entity object, including: extracting the entity object from the object to be converted according to multiple entity attributes defined in the object entity class; wherein the entity attributes include: user name, mobile phone number, login date, gender, password, bank card, and creation time.

[0051] More specifically, extracting multiple entity objects from the object to be converted according to multiple entity attributes defined in the object entity class includes: reading the value of each field in the object to be converted; corresponding each field with each entity attribute defined in the object entity class, and writing the value corresponding to each entity attribute into the object entity class to obtain the entity object.

[0052] For example, an object defines entity attributes such as user name, mobile phone number, login date, gender, password, bank card, and creation time. When converting the object to be converted into an entity object, read each field in the object to be converted and match each field with the pre-defined entity attributes. If a field is consistent with an entity attribute, the value of the field is used as the value of the corresponding entity attribute. Multiple fields are processed in this way to obtain an entity object.

[0053] Step S120: Call the object conversion processing class of the object conversion operation tool class, and convert the entity object into a Map form based on the reflection mechanism according to the configuration information of the object conversion operation tool class, wherein the configuration information is configured at least according to the object conversion rules preset in the object conversion processing class.

[0054] Figure 2 A schematic diagram of the process of converting an entity object into a Map by a conversion object processing class according to an embodiment of the present application is shown. Figure 2 It can be seen that this embodiment includes: taking the entity object as the input parameter of the conversion object processing class, and the conversion object processing class can use the following reflection mechanism instruction Field[]fields=obj.getClass().getDeclaredFields() to obtain all the attributes in the object to be converted and the attribute values ​​corresponding to each attribute from the entity object.

[0055] As described above, in some embodiments, the object conversion rule includes at least one of the following: a renderer, an exclusion attribute set, an inclusion attribute set, an attribute alias set, and a date specification format; wherein a unified external data format is defined in the renderer; at least one attribute that does not need to be converted is defined in the exclusion attribute set; multiple attributes that need to be converted are defined in the inclusion attribute set; a mapping relationship between the internal name and the external name of at least one attribute is defined in the attribute alias set; and a specified format for displaying time is defined in the date specification format.

[0056] When the entity object is converted into a Map form based on the reflection mechanism according to the configuration information of the object conversion operation tool class, an initial Map is established, and the key-value pairs in the initial Map are all empty; based on the reflection mechanism, each entity attribute in the entity object and the corresponding attribute value are obtained; then a for loop is used to traverse all the attributes, and for an entity attribute, it is determined whether the entity attribute belongs to the included attribute set. If the entity attribute does not belong to the included attribute set, the entity attribute is ignored and the next entity attribute is traversed; if the entity attribute belongs to the included attribute set, it is determined whether the entity attribute belongs to the excluded attribute set. If the entity attribute belongs to the excluded attribute set, the entity attribute is ignored and the next entity attribute is traversed; if the entity attribute does not belong to the excluded attribute set, it is determined whether the entity attribute belongs to the attribute set. If the entity attribute belongs to the attribute alias set, the alias of the entity attribute is returned to the Map, and the next entity attribute is traversed; if the entity attribute does not belong to the attribute alias set, it is determined whether the entity attribute is of date type. If the entity attribute is of date type, the attribute value of the entity attribute is returned to the Map in the date specified format using a security thread. If the entity attribute is not of date type, it is determined whether all entity attributes have been traversed. If all entity attributes have not been traversed, the next entity attribute is traversed; if all entity attributes have been traversed, it is determined whether the rendering class of the entity attribute is empty. If the rendering class of the entity attribute is empty, the next entity attribute is traversed. If the rendering class of the entity attribute is not empty, a Map is returned according to the unified external data format defined in the renderer.

[0057] After traversing all entity attributes and processing them according to the above logic, each entity attribute and the corresponding attribute value are returned to the initial Map according to the unified external data format defined in the renderer, and the updated initial Map is returned as the final Map form of the object to be converted.

[0058] The object conversion method of the present application is applicable to various objects, especially nested entity classes and List objects. For example, a user (Person) object contains a wallet (Wallet) object, and the wallet contains a bank card (BankCard) object, and the object may be a collection, that is, there may be multiple bank cards in the wallet. This is a typical complex nested entity class, and the present application is particularly suitable for such complex objects to be converted.

[0059] Depend on Figure 1It can be seen from the method shown that the present application provides a method for converting an object into a Map, and provides a tool that can convert a complex object into a Map object. Specifically, an object entity class is constructed, and multiple entity attributes of the object to be converted are defined in the object entity class; then an object conversion processing class is constructed, and conversion rules for converting the object to be converted into a Map are defined in the object conversion processing class; then the object entity class and the object conversion processing class are integrated into an object conversion operation tool class. When converting an object, the object is used as an input parameter. First, based on the object entity class, the received object is extracted into an entity object consisting of multiple entity attributes and entity attribute values ​​defined in the object entity class, and then based on the object conversion processing class, one or more attributes of the entity object are converted according to the object conversion rules defined in the object conversion processing class to obtain the Map form of the object to be converted and return it. This application first converts the object to be converted into a predefined entity object containing multiple entity attributes, and then converts the entity object into a Map form according to a preset conversion rule, thereby providing a unified conversion tool to the outside world, significantly reducing the labor cost and code maintenance cost of converting the object into a Map, and significantly improving the efficiency of software engineering development; the conversion tool is highly scalable, and both the object entity class and the object conversion processing class can be defined according to actual business needs, and during the application process, they can also be modified at any time according to business needs, supporting immediate use, and having strong real-time and practicality; and the conversion accuracy is high, which significantly reduces the risk of software project development.

[0060] Figure 3 The device for implementing the object conversion into Map according to an embodiment of the present application is shown. Figure 3 It can be seen that the implementation device 300 for converting an object into a Map includes:

[0061] The first calling unit 310 is used to call the object entity class of the pre-built object conversion operation tool class to extract the received object to be converted as an entity object, wherein a plurality of entity attributes of the object are defined in the object entity class;

[0062] The second calling unit 320 is used to call the object conversion processing class of the object conversion operation tool class, and convert the entity object into a Map form based on the reflection mechanism according to the configuration information of the object conversion operation tool class, wherein the configuration information is configured at least according to the object conversion rules preset in the object conversion processing class.

[0063] In some embodiments of the present application, in the above-mentioned device for converting an object into a Map, the first calling unit 310 is used to extract entity objects from the object to be converted according to multiple entity attributes defined in the object entity class; wherein the entity attributes include: user name, mobile phone number, login date, gender, password, bank card, and creation time.

[0064] In some embodiments of the present application, in the above-mentioned device for converting an object into a Map, the first calling unit 310 is used to read the value of each field in the object to be converted; correspondence between each field and each entity attribute defined in the object entity class, and write the value corresponding to each entity attribute into the object entity class to obtain the entity object.

[0065] In some embodiments of the present application, in the above-mentioned device for converting an object into a Map, the object conversion rule includes at least one of the following: a renderer, an exclusion attribute set, an inclusion attribute set, an attribute alias set, and a date specification format; wherein a unified external data format is defined in the renderer; at least one attribute that does not need to be converted is defined in the exclusion attribute set; multiple attributes that need to be converted are defined in the inclusion attribute set; a mapping relationship between the internal name and the external name of at least one attribute is defined in the attribute alias set; and a specified format for displaying time is defined in the date specification format.

[0066] In some embodiments of the present application, in the above-mentioned device for converting an object into a Map, the second calling unit 320 is used to construct a Map, and obtain each entity attribute in the entity object and the corresponding attribute value based on the reflection mechanism; traverse each entity attribute in the entity object in turn, and determine whether an entity attribute belongs to an inclusion attribute set. If the entity attribute does not belong to the inclusion attribute set, ignore the entity attribute and traverse the next entity attribute; if the entity attribute belongs to the inclusion attribute set, determine whether the entity attribute belongs to the exclusion attribute set. If the entity attribute belongs to the exclusion attribute set, ignore the entity attribute and traverse the next entity attribute; if the entity attribute does not belong to the exclusion attribute set, determine whether the entity attribute belongs to the attribute alias set. If the entity attribute belongs to In the attribute alias set, the alias of the entity attribute is returned to the Map, and the next entity attribute is traversed; if the entity attribute does not belong to the attribute alias set, it is determined whether the entity attribute is of date type. If the entity attribute is of date type, a safe thread is used to return the attribute value of the entity attribute to the Map in the date specified format. If the entity attribute is not of date type, it is determined whether all entity attributes have been traversed. If all entity attributes have not been traversed, the next entity attribute is traversed; if all entity attributes have been traversed, it is determined whether the rendering class of the entity attribute is empty. If the rendering class of the entity attribute is empty, the next entity attribute is traversed. If the rendering class of the entity attribute is not empty, a Map is returned according to the unified external data format defined in the renderer.

[0067] In some embodiments of the present application, in the above-mentioned device for converting an object into a Map, the object includes: a nested entity class, and a List object.

[0068] It should be noted that the above-mentioned device 300 for converting an object into a Map can implement the above-mentioned method of converting an object into a Map one by one, which will not be described in detail.

[0069] Figure 4 A schematic diagram showing the structure of a computer device according to an embodiment of the present application is shown. Figure 4As shown, the internal structure of the computer device may include a processor, a memory, a network interface and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client via a network connection. The computer program is executed by the processor to convert the object into the function or step of the method service side of the Map.

[0070] In one embodiment, the computer device provided by the present application includes a memory and a processor, the memory stores a database and a computer program that can be run on the processor, and when the processor executes the computer program, it implements the functions or steps of the method of converting an object into a Map in the present application.

[0071] In one embodiment, a computer device is also provided. The computer device may be a user side, and its internal structure diagram may be as shown in FIG. Figure 5 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server through a network connection. When the computer program is executed by the processor, the object is converted into the function or step of the Map method.

[0072] In one embodiment, a computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed by a processor, the functions or steps of the method for converting an object into a Map in the present application are implemented.

[0073] It should be noted that the above functions or steps that can be implemented by the computer device or computer-readable storage medium can refer to the relevant descriptions of the service side and the user side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.

[0074] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0075] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0076] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.

Claims

1. A method for converting an object into a Map, characterized in that: include: Calling the object entity class of the pre-built object conversion operation tool class, extracting the received object to be converted as an entity object, wherein a plurality of entity attributes of the object are defined in the object entity class; The object conversion processing class of the object conversion operation tool class is called, and according to the configuration information of the object conversion operation tool class, the entity object is converted into a Map form based on the reflection mechanism, wherein the configuration information is configured at least according to the object conversion rules preset in the object conversion processing class.

2. The method for converting an object into a Map according to claim 1, characterized in that: The calling of the object entity class of the pre-built object conversion operation tool class to extract the received object to be converted into an entity object includes: Extracting entity objects from the object to be converted according to a plurality of entity attributes defined in the object entity class; The entity attributes include: user name, mobile phone number, login date, gender, password, bank card, and creation time.

3. The method for converting an object into a Map according to claim 2, characterized in that: The step of extracting a plurality of entity objects from the object to be converted according to a plurality of entity attributes defined in the object entity class comprises: Read the value of each field in the object to be converted; The corresponding relationship between each field and each entity attribute defined in the object entity class is established, and the value corresponding to each entity attribute is written into the object entity class to obtain the entity object.

4. The method for converting an object into a Map according to claim 1, characterized in that: The object conversion rule includes at least one of the following: a renderer, an exclusion attribute set, an inclusion attribute set, an attribute alias set, and a date specified format; Wherein, a unified external data format is defined in the renderer; At least one attribute that does not need to be converted is defined in the exclusion attribute set; A plurality of attributes that need to be converted are defined in the included attribute set; A mapping relationship between an internal name and an external name of at least one attribute is defined in the attribute alias set; The date designation format includes a designation format for displaying time.

5. The method for converting an object into a Map according to claim 4, characterized in that: The converting the entity object into a Map form according to the configuration information of the object conversion operation tool class includes: Construct a Map, and obtain each entity attribute and the corresponding attribute value in the entity object based on the reflection mechanism; Traversing each entity attribute in the entity object in turn, determining whether an entity attribute belongs to the included attribute set, and if the entity attribute does not belong to the included attribute set, ignoring the entity attribute and traversing the next entity attribute; If the entity attribute belongs to the inclusion attribute set, determine whether the entity attribute belongs to the exclusion attribute set; if the entity attribute belongs to the exclusion attribute set, ignore the entity attribute and traverse the next entity attribute; If the entity attribute does not belong to the exclusion attribute set, determine whether the entity attribute belongs to the attribute alias set; if the entity attribute belongs to the attribute alias set, return the alias of the entity attribute to the Map, and traverse the next entity attribute; If the entity attribute does not belong to the attribute alias set, it is determined whether the entity attribute is of date type. If the entity attribute is of date type, a security thread is used to return the attribute value of the entity attribute to the Map in the date specified format. If the entity attribute is not of date type, it is determined whether all entity attributes have been traversed. If all entity attributes have not been traversed, the next entity attribute is traversed. If all entity attributes have been traversed, determine whether the rendering class of the entity attribute is empty. If the rendering class of the entity attribute is empty, traverse the next entity attribute. If the rendering class of the entity attribute is not empty, return a Map according to the unified external data format defined in the renderer.

6. The method for converting an object into a Map according to any one of claims 1 to 5, characterized in that: The objects include: nested entity classes, and List objects.

7. The method for converting an object into a Map according to any one of claims 1 to 5, characterized in that: The object conversion operation tool class is integrated according to the following method: In the operation tool class development file package, establish the object conversion operation tool class; The object entity class is defined in the object conversion operation tool class, and the object entity class includes multiple entity attributes of the object, so that the object entity class reads the value of each field in the object to be converted, and the correspondence between each field and each entity attribute defined in the object entity class is written into the object entity class to obtain the entity object; The object conversion processing class is defined in the object conversion operation tool class, and the object conversion rules pre-set in the object conversion processing class enable the object conversion processing class to obtain the source data of each attribute in the entity object obtained by the object entity class based on the reflection mechanism; The object conversion rule provided by the object conversion processing class is embedded in the object conversion operation tool class as configuration information, and the object conversion processing class is defined to convert the entity object into a Map format according to the configuration information.

8. A device for converting an object into a Map, characterized in that: The device for converting the object into a Map includes: A first calling unit is used to call an object entity class of a pre-built object conversion operation tool class to extract the received object to be converted as an entity object, wherein a plurality of entity attributes of the object are defined in the object entity class; The second calling unit is used to call the object conversion processing class of the object conversion operation tool class, and convert the entity object into a Map form based on the reflection mechanism according to the configuration information of the object conversion operation tool class, wherein the configuration information is configured at least according to the object conversion rules preset in the object conversion processing class.

9. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program, characterized in that: The computer program implements the method according to any one of claims 1 to 7 when instructed by a processor.