CN109408569A - JSON data transfer device, device, computer equipment and storage medium - Google Patents
JSON data transfer device, device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN109408569A CN109408569A CN201811138514.8A CN201811138514A CN109408569A CN 109408569 A CN109408569 A CN 109408569A CN 201811138514 A CN201811138514 A CN 201811138514A CN 109408569 A CN109408569 A CN 109408569A
- Authority
- CN
- China
- Prior art keywords
- json
- attribute
- name
- common java
- java class
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000012546 transfer Methods 0.000 title claims abstract description 33
- 238000003860 storage Methods 0.000 title claims abstract description 18
- 230000007246 mechanism Effects 0.000 claims abstract description 31
- 238000006243 chemical reaction Methods 0.000 claims description 25
- 238000004590 computer program Methods 0.000 claims description 20
- 230000005540 biological transmission Effects 0.000 claims description 12
- 230000004044 response Effects 0.000 abstract description 6
- 238000000034 method Methods 0.000 description 32
- 230000008569 process Effects 0.000 description 12
- 230000006870 function Effects 0.000 description 9
- 235000010627 Phaseolus vulgaris Nutrition 0.000 description 4
- 244000046052 Phaseolus vulgaris Species 0.000 description 4
- 238000012545 processing Methods 0.000 description 4
- 238000010586 diagram Methods 0.000 description 3
- 238000013507 mapping Methods 0.000 description 3
- 239000003550 marker Substances 0.000 description 3
- 238000001514 detection method Methods 0.000 description 2
- 238000011161 development Methods 0.000 description 2
- 238000005194 fractionation Methods 0.000 description 2
- 238000012423 maintenance Methods 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 241000406668 Loxodonta cyclotis Species 0.000 description 1
- 230000002159 abnormal effect Effects 0.000 description 1
- 230000005856 abnormality Effects 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 230000006399 behavior Effects 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 210000001072 colon Anatomy 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000010485 coping Effects 0.000 description 1
- 230000008878 coupling Effects 0.000 description 1
- 238000010168 coupling process Methods 0.000 description 1
- 238000005859 coupling reaction Methods 0.000 description 1
- 238000013497 data interchange Methods 0.000 description 1
- 238000013501 data transformation Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000002708 enhancing effect Effects 0.000 description 1
- 238000001914 filtration Methods 0.000 description 1
- 230000010365 information processing Effects 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 230000014759 maintenance of location Effects 0.000 description 1
- 235000020069 metaxa Nutrition 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000002360 preparation method Methods 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
Landscapes
- Stored Programmes (AREA)
Abstract
The invention discloses a kind of JSON data transfer device, device, computer equipment and storage mediums, which comprises receives JSON data and the example is melted into JSON object;Using reflection mechanism, the attribute-name and attribute value of JSON object are obtained;Preset common java class set is traversed, the attribute-name of each common java class in set is obtained using reflection mechanism;For each common java class, compared with the attribute-name of common java class is carried out one by one with the attribute-name of JSON object, if the two is equal, the common java class is then instantiated as common Java object, and the corresponding attribute value of attribute-name identical with the common java class in JSON object is assigned to common Java object.JSON data are split and are mapped in common Java object by technical solution of the present invention, are conducive to save system memory resource and expense, are improved system response time.
Description
Technical field
The present invention relates to field of information processing more particularly to JSON data transfer device, device, computer equipment and storages
Medium.
Background technique
Currently, be mostly between Web service end and Web client or between Web service end and other server-sides with
JSON format carries out data exchange.
JSON (JavaScript Object Notation) is a kind of data interchange format of light weight, it is easy by people
It reads and writes, and be easy to be generated and parsed by machine.It with text formatting storing data, be totally independent of C, C++, C#,
The programming languages such as Java, JavaScript, Perl, Python can be programmed language and easily use.
In interactive process between the systems, by JSON data conversion that other systems send at the number locally needed
It is sent according to format, or by local data conversion at JSON format, is the normality in data exchange process.Wherein, will
After JSON data conversion is at local data, local system carries out various related operations usually using the data after converting into foundation.Example
Such as, it when including different operational orders in the JSON data that local system receives, needs to look into different databases
It askes, then the data after conversion are assigned to different database query modules by local system.
If JSON data structure is complicated, data volume is big, then the local data being converted to JSON data is equally huge
Greatly, the memory source of occupancy is more, and when carrying out assignment, copy, the operation such as transmitting to the local data, will affect and is
The operational efficiency of system.It, can be increasingly to the occupancy of memory source especially to the demanding large-scale Web system of real time response speed
It is more, to influence the response speed of whole system.
Summary of the invention
The embodiment of the present invention provides a kind of JSON data transfer device, device, computer equipment and storage medium, to solve
Because committed memory resource caused by JSON data are excessive is more, the problem of influencing system response time.
A kind of JSON data transfer device, comprising:
The JSON data that client is sent are received, and the JSON data instance is melted into JSON object;
Using reflection mechanism, obtain the attribute-name of the JSON object, and with each attribute in the JSON object
The corresponding attribute value of name;
Preset common java class set is traversed, and is obtained in the preset common java class set using reflection mechanism
The attribute-name of each common java class;
For each common java class in the preset common java class set, by the attribute-name of the common java class
Compared with being carried out one by one with the attribute-name of the JSON object, if all properties name of the common java class is included in the JSON
In the attribute-name of object, then the common java class is instantiated as common Java object, and will be general with this in the JSON object
The logical corresponding attribute value of the identical attribute-name of java class is assigned to the common Java object.
A kind of JSON data conversion device, comprising:
Module is instantiated, is melted into JSON for receiving the JSON data of client transmission, and by the JSON data instance
Object;
Reflect value module, for using reflection mechanism, obtain the attribute-name of the JSON object, and with this JSON pairs
The corresponding attribute value of each attribute-name as in;
Value module is traversed, obtains described preset for traversing preset common java class set, and using reflection mechanism
Common java class set in each common java class attribute-name;
Compare assignment module, it, will be described for being directed to each common java class in the preset common java class set
Compared with the attribute-name of common java class carries out one by one with the attribute-name of the JSON object, if all categories of the common java class
Property name be included in the attribute-name of the JSON object, then the common java class is instantiated as common Java object, and by institute
It states the corresponding attribute value of identical with common java class attribute-name in JSON object and is assigned to the common Java object.
A kind of computer equipment, including memory, processor and storage are in the memory and can be in the processing
The computer program run on device, the processor realize above-mentioned JSON data transfer device when executing the computer program
Step.
A kind of computer readable storage medium, the computer-readable recording medium storage have computer program, the meter
The step of calculation machine program realizes above-mentioned JSON data transfer device when being executed by processor.
Above-mentioned JSON data transfer device, device, computer equipment and storage medium receive the JSON number that client is sent
According to, and the JSON data instance is melted into JSON object;Using reflection mechanism, obtain in real time JSON object attribute-name and
Attribute value;Preset common java class set is traversed, is obtained in preset common java class set using reflection mechanism
Then the attribute-name of each common java class compares the attribute-name of JSON object and the attribute-name of each common java class
Compared with if the attribute-name of JSON object is equal with the attribute-name of common java class, which is instantiated as commonly
Java object, and attribute value corresponding to the attribute-name of the JSON object is assigned to the common Java object, thus realize by
One JSON data is split, and is mapped in multiple common Java objects.Due to using reflection mechanism, entire JSON data turn
The process of changing is real-time dynamicly;According to the needs of practical application, the JSON data fractionation that structure is complicated, data volume is big is converted into
Common Java object, saves system memory resource and expense, improves system response time.
Detailed description of the invention
In order to illustrate the technical solution of the embodiments of the present invention more clearly, below by institute in the description to the embodiment of the present invention
Attached drawing to be used is needed to be briefly described, it should be apparent that, the accompanying drawings in the following description is only some implementations of the invention
Example, for those of ordinary skill in the art, without any creative labor, can also be according to these attached drawings
Obtain other attached drawings.
Fig. 1 is an application environment schematic diagram of JSON data transfer device in one embodiment of the invention;
Fig. 2 is the flow chart of JSON data transfer device in one embodiment of the invention;
Fig. 3 be in one embodiment of the invention in JSON data transfer device by JSON data conversion at data connection object
Flow chart;
Fig. 4 is the flow chart of step S1 in JSON data transfer device in one embodiment of the invention;
Fig. 5 is the flow chart of step S4 in JSON data transfer device in one embodiment of the invention;
Fig. 6 is the schematic diagram of JSON data conversion device in one embodiment of the invention;
Fig. 7 is the schematic diagram of computer equipment in one embodiment of the invention.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Site preparation description, it is clear that described embodiments are some of the embodiments of the present invention, instead of all the embodiments.Based on this hair
Embodiment in bright, every other implementation obtained by those of ordinary skill in the art without making creative efforts
Example, shall fall within the protection scope of the present invention.
JSON data transfer device provided by the present application, can be applicable in the application environment such as Fig. 1, wherein client is
The computer terminal of JSON data, including but not limited to browser, cell phone application, PC host are sent, server, intelligence is eventually
End etc..Server-side is the computer equipment converted to JSON data or component, can be by server or server
Cluster composition.Destination client is the computer equipment or virtual terminal for having request of data to server-side, can be taken with cell phone application
Business device etc.;The JSON data after conversion are sent destination client by server-side.Between client and server-side, server-side and mesh
It marks by network connection between client, network can be cable network or wireless network.It is provided in an embodiment of the present invention
JSON data transfer device is applied to server-side.
In one embodiment, as shown in Fig. 2, providing a kind of JSON data transfer device, specific implementation flow includes
Following steps:
S1: the JSON data that client is sent are received, and JSON data instance is melted into JSON object.
In the present embodiment, JSON data can be stored in a manner of JSON file.JSON file is with ASCII
(American Standard Code for Information Interchange, ASCII) coding
Mode stores, and independent of operating system, quickly can be read or be generated by computer program, be a kind of common data exchange
Format.
Wherein, ASCII is a set of computer code's system based on the Latin alphabet, is mainly used for showing current english and other
Western-European languages are single byte coded systems most general now.
JSON data are made of key-value pair (key-value), and key-value pair includes a key name and corresponding with the key name
Key assignments.One JSON data includes at least one key-value pair;It is separated between key name and key assignments by colon;Each key-value pair with
Comma terminates;Key name need to add quotation marks;Add quotation marks if key assignments is character type data, quotation marks are not added in non-character type data;One
There can be sub- JSON data in JSON data, each data in sub- JSON data using left bracket as starting, make by right bracket
To terminate.JSON file starts using opening brace as file, right braces is as the end of file, and sub- JSON data are included greatly with a left side
End as sub- JSON data of beginning, right braces number as sub- JSON data.
For example, a JSON file about student information can be expressed as follows:
Instantiation refers in the programming of object-oriented, creates the process of object.Object is data in Object-Oriented Programming
The basic unit of storage and processing, object include attribute-name and method.
JSON data instance is melted into JSON object by server-side, i.e. server-side creates new object, using JSON data as
The data flow of input carries out the process of assignment to newly-built object;After JSON object is newly-built to server-side and instantiation
The common name of object.
Server-side instantiates the JSON data of the JSON document form received, is converted into JSON object.
Specifically, JSON data being carried out unserializing can also be can be used by calling inside Java from tape function
Ready-made third party's tool, such as JSON-LIB, the FastJson of Ali company, the Gson of Google, the Jackson of open source
Deng.
Still by step S1 about the JSON file of student information for, by calling inside Java from tape function or third
Side's parsing JSON tool, the JSON object after instantiation are student's object, in the attribute and JSON file which includes
Key name corresponds, including " student name ", " age ", " class ";The object further includes a subobject " interim achievement ", son
The attribute of object includes " Chinese language " and " mathematics ".Key assignments corresponds in student's object's property value and JSON file.
S2: using reflection mechanism, obtains the attribute-name of JSON object, and corresponding with each attribute-name in the JSON object
Attribute value.
Reflection (Reflection) mechanism refers to accessible program, detection and modification itself state or one kind of behavior
Ability.Language based on reflection mechanism includes Python, OpenC++, MetaXa, Java etc..By taking Java reflection mechanism as an example,
In operating status, for any one class, it can determine the whole attributes and method of this class by Java reflection mechanism;For
Any one object can call its any one method and attribute, it might even be possible to modify the privately owned of an object
The value of private attribute.It, can be in the type of test object at runtime based on reflection mechanism;Pair of some class of dynamic construction
As;Detect the attribute and method of class;Any method for calling object;Modify the visibility of constructed fuction, method, attribute.
Server-side is by reflection mechanism, the attribute-name of available JSON object, and with each category in the JSON object
The property corresponding attribute value of name.
Specifically, server-side is by the forName () method for the Class class for calling Java included, with pair of JSON object
It is inputted as name is used as, the example for obtaining JSON object;GetFields () method is called to obtain with the example of obtained JSON object
Take attribute-name in JSON object;Continue to call get () method to obtain in the JSON object often with the example of obtained JSON object
The corresponding attribute value of a attribute-name.
For example, server-side can obtain its all properties name and category by reflection mechanism if JSON object is student information
Property value.
S3: the preset common java class set of traversal, and obtained in preset common java class set using reflection mechanism
The attribute-name of each common java class.
Common Java object is referred to as POJO (Plain Ordinary Java Object/Pure Old Java
Object).POJO is for special Java object, and POJO is used to emphasize that it is a common Java object, without
It is a special object.Special object, which is mainly used to refer to those, defers to specific Java object model, agreement or frame
The Java object of (such as EJB), and POJO is one other than Java language specification, unrestricted Java object.
Common Java object is the example of common java class, and the set of common java class is to be needed to carry out according to pre-set business
The set of the class of division.For example, if server-side needs the operation that accesses to three databases or tables of data, each database or
Tables of data needs different data as input, then usual server-side define three different POJO respectively to three databases or
Tables of data accesses operation, and therefore, server-side needs in the process of running, and preset three different common java class are real
Example turns to three POJO.
Still by taking the student information in step S1 as an example, server-side needs the operation that accesses to three tables of data, three numbers
It is Basic Information Table, preference blank, summary respectively according to table.Wherein, the field that Basic Information Table includes has student's
Name, age, class etc., the field for including in preference blank have the hobby etc. of student, include in summary
Field has the title etc. of the every subject of student.Three classes can be preset by system or developer, be essential information class respectively, emerging
Interest hobby class, achievement class;The attribute-name of three classes is corresponded with the field in three tables of data.Server-side uses reflection machine
System, obtains the attribute-name of each general category.
Specifically, common java class set can be defined in the form of static array, each element generation in array
The class name of one, table common java class.Server-side is by traversal array, using the class name of each common java class as input, and
The getDeclaredFields () method of calling is to obtain attribute all in such, until having traversed member all in array
Element.To obtain the attribute-name of all common java class.
S4: for each common java class in preset common java class set, by the attribute-name of common java class with
The attribute-name of JSON object is compared one by one, if all properties name of common java class is included in the attribute-name of JSON object
In, then the common java class is instantiated as common Java object, and by category identical with the common java class in JSON object
The property corresponding attribute value of name is assigned to common Java object.
Server-side needs to instantiate them after the attribute-name for obtaining each common java class, i.e., to each common
The attribute of java class carries out assignment.
Specifically, a preset common java class is taken, its all properties name is traversed, by the attribute of each common java class
Name is compared with the attribute-name in JSON object, if the attribute-name of common java class and some attribute famous prime minister in JSON object
Together, then server-side calls new () method, creates common Java object, and by attribute corresponding with the attribute-name in JSON object
Value is assigned to newly created common Java object.And so on, it is common until all common java class whole examples to be melted into
Until Java object.
In the present embodiment, the JSON data that client is sent are received, and the JSON data instance is melted into JSON pairs
As;Using reflection mechanism, the attribute-name and attribute value of JSON object are obtained in real time;Preset common java class set is carried out
Traversal obtains the attribute-name of each common java class in preset common java class set using reflection mechanism, then by JSON
The attribute-name of object is compared with the attribute-name of each common java class, if the attribute-name of JSON object and common java class
Attribute-name is equal, then the common java class is instantiated as common Java object, and will be corresponding to the attribute-name of the JSON object
Attribute value be assigned to the common Java object, JSON data are split to realize, and be mapped to multiple common Java
On object.Due to using reflection mechanism, the conversion process of entire JSON data is real-time dynamicly;According to the need of practical application
It wants, the JSON data fractionation that structure is complicated, data volume is big is converted into common Java object, system memory resource is saved and opens
Pin, improves system response time.
Further, in one embodiment, as shown in figure 3, after step s4, that is, being directed to preset common java class collection
Each common java class in conjunction, compared with the attribute-name of common java class is carried out one by one with the attribute-name of JSON object, if commonly
The all properties name of java class is included in the attribute-name of JSON object, then the common java class is instantiated as common Java pairs
As, and by the corresponding attribute value of attribute-name identical with the common java class in JSON object be assigned to common Java object it
Afterwards, JSON data transfer device further includes following steps:
S5: if receiving the data acquisition request of destination client, common Java object is converted into data transmission pair
As.
Data connection object is referred to as DTO (Data Transfer Object), is between not homologous ray or system
Different software layer between the data medium that carries out data transmission or exchange.
Destination client is the computer equipment or virtual terminal for having request of data to server-side.Usually for safety
Consider, server-side only passes information related with the request of data that destination client proposes, to guarantee other information
Safety.
For example, a tables of data of server-side has 50 fields, then corresponding common Java object has 50 attributes.But
It only needs to show 10 fields on the interface of destination client, then when destination client proposes data acquisition request, must not
Entire common Java object is transmitted to destination client, therefore, server-side is extracted from common Java object and obtained with data
Relevant 10 attributes of request are taken, and are converted into data connection object.
Specifically, the data acquisition request that destination client is sent can submit data acquisition request, number by Web page
According to the class name in acquisition request including data transmission class.Server-side uses reflection mechanism, using the class name of data transmission class as defeated
Enter parameter, obtains the attribute-name of data transmission class;Then by the attribute-name of the attribute-name of common Java object and data transmission class
It is compared, if the attribute-name of common Java object is identical as the data transmission attribute-name of class, calls new () method newly-built
Data connection object, and attribute value corresponding with the attribute-name of the common Java object is assigned to data connection object, thus
Complete the instantiation of data connection object.
S6: target data corresponding with data acquisition request in common Java object is sent to using data connection object
Destination client.
Data connection object after instantiating in step S5, it is corresponding to contain destination client data acquisition request
Target data.Data connection object can be sent to destination client by Web page or socket by server-side.
In the present embodiment, server-side uses reflection mechanism, by number relevant to the data acquisition request of destination client
According to, extracted from common Java object, generate data connection object simultaneously return to destination client.Due to common Java pairs
The attribute-name of elephant and the field name of tables of data are correspondingly, to be carried out data transmission by data connection object, will not be exposed
The data structure of entire tables of data, is conducive to data safety.
Further, as shown in figure 4, in one embodiment, for step S1, that is, receiving the JSON number that client is sent
According to, and JSON data instance is melted into JSON object, specifically comprise the following steps:
S11: the JSON data that client is sent are received.
Server-side can receive JSON data by Web page.In Web page preset service end need received data and
The data type of the data.It is such as defined in the list of Web page field " student name ", " age " and " class ", and
Corresponding data type is character type, integer and character type etc..
In addition, a marker bit can also be preset in Web page, this time sent belonging to JSON data for representing client
Request type.By insuring, for surrender and continuation of insurance for insurance, have in Web page insure, item is chosen in surrender or continuation of insurance, use
Family is chosen when submitting JSON data by client, so that the backstage Web is able to know which the JSON of the secondary submission belongs to
Request type.
Specifically, the JSON data received can be stored as JSON file by server-side.
S12: according to the request type of JSON data, interception corresponding with request type is read from preset configuration file
Path.
A global configuration table can be preset except server-side local or server-side, which can be
Simple text formatting is closed for recording the JSON data that server-side receives with class name, request type, the corresponding of interception path
System.Wherein, intercepting path is a file directory name in server-side.The corresponding class name of every JSON data, it is corresponding a kind of
Request type, a corresponding interception path.
For example, the received JSON data of server-side are about policy information, about supplier information, about member
Work information etc..Be declaration form object about the corresponding object naming of policy information, corresponding interceptions path is " baodan ";
Be supply quotient object about the corresponding object naming of supplier information, corresponding interceptions path is " gongyingshang ";With
It is employee's object about the corresponding object naming of employee information, corresponding interception path is " yuangong ".
Intercepting path can configure in file SpringMVC.xml.File SpringMVC.xml is under Spring frame
A configuration file.Spring is the design level frame an of open source code, is the Java exploitation frame an of lightweight
Frame, what he solved is the loose coupling problem of Business Logic He other each layers.For large-scale Web application system, usually first will
Spring is deployed on server, and then further according to the needs of practical application, secondary development is done on Spring.It does so sufficiently
The existing interface of Spring frame is utilized, avoids the development of simple repeatability, and can quickly develop and be suitble to itself industry
The application that business needs.
Specifically, the marker bit in JSON data that server-side detection receives, then according to marker bit in global configuration
Interception path corresponding to the JSON data is inquired in table.For example, search is mvc:mapping in SpringMVC.xml
Value after path field:
<mvc:mapping path="/shouxian/* "/>
Wherein, " mvc:mapping path " is represented in Spring configuration file for defining the label of filtration path;
" baodan " represents the catalogue of declaration form;"/shouxian/* " represents the All Files under baodan catalogue, be configured so that so that
The request event that All Files trigger under baodan catalogue, can be intercepted.
S13: JSON data distribution is given and intercepts the corresponding blocker in path, by JSON data instance in blocker
At JSON object.
Blocker is the corresponding executing subject for intercepting JSON data under path of processing.
Specifically, server-side can search for the value after bean class field in SpringMVC.xml:
<bean class="com.base.baodan"></bean>
Wherein, " bean class " represents the label of the class of blocker;" com.base.baodan " is for interception path
The class name of the blocker of "/baodan/* ".Such method be used under declaration form catalogue All Files trigger request event into
Row intercept process.It is to be appreciated that different interception paths corresponds to different blockers, and different business demands is corresponding different
Interception path, server-side can be handled JSON data distribution to different blocker, to realize the classification to JSON data
And shunting.
In the present embodiment, server-side can classify to the JSON data received according to the request type belonging to it
And shunting, it is handled with the blocker for being given to different, allows to customize more JSON data transformation interfaces, improve simultaneously
Treatment effeciency.
Further, as shown in figure 5, in one embodiment, for step S4, that is, being directed to preset common java class set
In each common java class, compared with the attribute-name of the attribute-name of common java class and JSON object is carried out one by one, if commonly
The all properties name of java class is included in the attribute-name of JSON object, then the common java class is instantiated as common Java pairs
As, and the corresponding attribute value of attribute-name identical with the common java class in JSON object is assigned to common Java object, have
Body may include following specific steps:
S41: it is added to the attribute-name of JSON object as array element in the first array.
Specifically, server-side creates an interim array, as the first array, and the JSON that will be obtained by reflection mechanism
The attribute-name of object is all added in first array.
S42: the attribute-name of common java class each in preset common java class set is added to as array element
In second array, and delete the attribute-name of duplicate common java class in the second array.
Due to the common java class in preset common java class set be according to different business need it is preset, data it
Between the possibility that overlaps, therefore, it is necessary to delete wherein duplicate attribute-name.For example, three relevant to policy information general
Logical java class, is respectively used to different business processings, then the shared attribute-name in three common java class may have declaration form odd numbers,
Insurer's name etc..
Specifically, server-side creates an interim array, as the second array, and will obtain by reflection mechanism common
The attribute-name of java class is all added in second array, and deletes duplicate attribute-name in the second array.
S43: the first array is compared with the second array, if the element of the element number of the first array and the second array
Number is equal, and the element value of the first array is equal with the element value of the second array, then is instantiated as common java class general
Logical Java object, and the corresponding attribute value of attribute-name identical with the common java class in JSON object is assigned to common Java
Object.
Specifically, server-side can call list.size () method to obtain the length and the second array of the first array respectively
Length, to judge whether the element number of two arrays equal;If element number is equal, server-side can call equals
Whether () method compares each element value in array equal;If each element value is equal, common java class is instantiated as
Common Java object, and the corresponding attribute value of attribute-name identical with the common java class in JSON object is assigned to commonly
Java object.
In the present embodiment, before common java class example is melted into common Java object, compared in a manner of array
Whether the attribute-name of JSON object and the attribute-name of common java class are essentially equal, the example again in the case where the two is essentially equal
Change common Java object, if in the case where avoiding missing JSON data, being because of caused by the instantiation failure of common java class
System is abnormal, improves the safety and stability of system.
It further, in one embodiment, i.e., will be each general in preset common java class set after step S42
The attribute-name of logical java class is added in the second array as array element, and deletes duplicate common java class in the second array
Attribute-name after, comprise the following specific steps that:
S44: the first array is compared with the second array, if the element of the element number of the first array and the second array
Number is unequal or the element value of the first array and the element value of the second array it is unequal, then output comprising the first array with
The exception information of the difference set of second array.
Specifically, if the element number of the element number of the first array and the second array is unequal or the first array
Element value and the element value of the second array are unequal, then the first array and the second array are carried out subtraction by server-side, with defeated
The attribute-name that the element value that the difference set of array includes out, i.e. JSON object have more or lack than common java class.Exception information is
When there is class instantiation failure, for the information for system maintenance personnel or developer's orientation problem.Exception information includes belonging to
Object name or class name belonging to property name, attribute-name.
In the present embodiment, server-side is using element value different in the first array and the second array as the one of exception information
Part is exported, and as warning information, can be convenient system maintenance personnel or developer's orientation problem.
It should be understood that the size of the serial number of each step is not meant that the order of the execution order in above-described embodiment, each process
Execution sequence should be determined by its function and internal logic, the implementation process without coping with the embodiment of the present invention constitutes any limit
It is fixed.
In one embodiment, a kind of JSON data conversion device is provided, the JSON data conversion device and above-described embodiment
Middle JSON data transfer device corresponds.As shown in fig. 6, the JSON data conversion device includes instantiation module 61, reflection
Value module 62, compares assignment module 64 at traversal value module 63.Detailed description are as follows for each functional module:
Module 61 is instantiated, is melted into JSON pairs for receiving the JSON data of client transmission, and by JSON data instance
As;
Reflect value module 62, for use reflection mechanism, obtain JSON object attribute-name, and with the JSON object
In the corresponding attribute value of each attribute-name;
Value module 63 is traversed, for traversing preset common java class set, and it is preset using reflection mechanism acquisition
The attribute-name of each common java class in common java class set;
Compare assignment module 64, it, will be common for being directed to each common java class in preset common java class set
Compared with the attribute-name of java class carries out one by one with the attribute-name of JSON object, if all properties name of common java class is included in
In the attribute-name of JSON object, then the common java class is instantiated as common Java object, and will be general with this in JSON object
The logical corresponding attribute value of the identical attribute-name of java class is assigned to common Java object.
Further, JSON data conversion device further include:
Conversion module, if the data acquisition request for receiving destination client, common Java object is converted into
Data connection object;
Sending module, for using data connection object by target corresponding with data acquisition request in common Java object
Data are sent to destination client.
Further, instantiation module 61 includes:
Receiving submodule, for receiving the JSON data of client transmission;
Reading submodule is read and request class for the request type according to JSON data from preset configuration file
The corresponding interception path of type;
Matched sub-block intercepts the corresponding blocker in path for giving JSON data distribution, will in blocker
JSON data instance is melted into JSON object.
Further, comparing assignment module 64 includes:
First builds a group submodule, for being added to the attribute-name of JSON object as array element in the first array;
Second builds a group submodule, for using the attribute-name of java class each common in preset common java class set as
Array element is added in the second array, and deletes the attribute-name of duplicate common java class in the second array;
Compare assignment submodule, for the first array to be compared with the second array, if the element number of the first array
It is equal with the element number of the second array, and the element value of the first array is equal with the element value of the second array, then it will be common
Java class is instantiated as common Java object, and by the corresponding attribute of attribute-name identical with the common java class in JSON object
Value is assigned to common Java object.
Further, compare assignment module 64 further include:
Abnormality alarming submodule, for the first array to be compared with the second array, if the element number of the first array
With the element number of the second array is unequal or the element value of the first array and the element value of the second array it is unequal, then it is defeated
The exception information of difference set out comprising the first array and the second array.
Specific about JSON data conversion device limits the limit that may refer to above for JSON data transfer device
Fixed, details are not described herein.Modules in above-mentioned JSON data conversion device can fully or partially through software, hardware and its
Combination is to realize.Above-mentioned each module can be embedded in the form of hardware or independently of in the processor in computer equipment, can also be with
It is stored in the memory in computer equipment in a software form, in order to which processor calls the above modules of execution corresponding
Operation.
In one embodiment, a kind of computer equipment is provided, which can be server, internal junction
Composition can be as shown in Figure 7.The computer equipment include by system bus connect processor, memory, network interface and
Database.Wherein, the processor of the computer equipment is for providing calculating and control ability.The memory packet of the computer equipment
Include non-volatile memory medium, built-in storage.The non-volatile memory medium is stored with operating system, computer program and data
Library.The built-in storage provides environment for the operation of operating system and computer program in non-volatile memory medium.The calculating
The network interface of machine equipment is used to communicate with external terminal by network connection.When the computer program is executed by processor with
Realize a kind of JSON data transfer device.
In one embodiment, a kind of computer equipment is provided, including memory, processor and storage are on a memory
And the computer program that can be run on a processor, processor realize JSON data in above-described embodiment when executing computer program
The step of conversion method, such as step S1 shown in Fig. 2 to step S4.Alternatively, processor is realized when executing computer program
State the function of each module/unit of JSON data conversion device in embodiment, such as module 61 shown in Fig. 6 is to the function of module 64
Energy.To avoid repeating, which is not described herein again.
In one embodiment, a computer readable storage medium is provided, computer program, computer program are stored thereon with
JSON data transfer device in above method embodiment is realized when being executed by processor, alternatively, the computer program is by processor
The function of each module/unit in JSON data conversion device in above-mentioned apparatus embodiment is realized when execution.To avoid repeating, here
It repeats no more.
Those of ordinary skill in the art will appreciate that realizing all or part of the process in above-described embodiment method, being can be with
Relevant hardware is instructed to complete by computer program, the computer program can be stored in a non-volatile computer
In read/write memory medium, the computer program is when being executed, it may include such as the process of the embodiment of above-mentioned each method.Wherein,
To any reference of memory, storage, database or other media used in each embodiment provided herein,
Including non-volatile and/or volatile memory.Nonvolatile memory may include read-only memory (ROM), programming ROM
(PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM) or flash memory.Volatile memory may include
Random access memory (RAM) or external cache.By way of illustration and not limitation, RAM is available in many forms,
Such as static state RAM (SRAM), dynamic ram (DRAM), synchronous dram (SDRAM), double data rate sdram (DDRSDRAM), enhancing
Type SDRAM (ESDRAM), synchronization link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM
(RDRAM), direct memory bus dynamic ram (DRDRAM) and memory bus dynamic ram (RDRAM) etc..
It is apparent to those skilled in the art that for convenience of description and succinctly, only with above-mentioned each function
Can unit, module division progress for example, in practical application, can according to need and by above-mentioned function distribution by different
Functional unit, module are completed, i.e., the internal structure of described device is divided into different functional unit or module, more than completing
The all or part of function of description.
Embodiment described above is merely illustrative of the technical solution of the present invention, rather than its limitations;Although referring to aforementioned reality
Applying example, invention is explained in detail, those skilled in the art should understand that: it still can be to aforementioned each
Technical solution documented by embodiment is modified or equivalent replacement of some of the technical features;And these are modified
Or replacement, the spirit and scope for technical solution of various embodiments of the present invention that it does not separate the essence of the corresponding technical solution should all
It is included within protection scope of the present invention.
Claims (10)
1. a kind of JSON data transfer device, which is characterized in that the JSON data transfer device includes:
The JSON data that client is sent are received, and the JSON data instance is melted into JSON object;
Using reflection mechanism, obtain the attribute-name of the JSON object, and with each attribute-name pair in the JSON object
The attribute value answered;
Preset common java class set is traversed, and is obtained in the preset common java class set each using reflection mechanism
The attribute-name of common java class;
For each common java class in the preset common java class set, by the attribute-name of the common java class and institute
The attribute-name for stating JSON object is compared one by one, if all properties name of the common java class is included in the JSON object
Attribute-name in, then the common java class is instantiated as common Java object, and will be common with this in the JSON object
The corresponding attribute value of the identical attribute-name of java class is assigned to the common Java object.
2. JSON data transfer device as described in claim 1, which is characterized in that be directed to the preset common java class
Each common java class in set, the attribute-name of the common java class and the attribute-name of the JSON object are compared one by one
Compared with if all properties name of the common java class is included in the attribute-name of the JSON object, by the common java class
It is instantiated as common Java object, and by the corresponding attribute value of attribute-name identical with the common java class in the JSON object
It is assigned to after the common Java object, the JSON data transfer device further include:
If receiving the data acquisition request of destination client, the common Java object is converted into data connection object;
Using the data connection object by target data corresponding with the data acquisition request in the common Java object
It is sent to the destination client.
3. JSON data transfer device as described in claim 1, which is characterized in that the JSON number for receiving client and sending
According to, and the JSON data instance is melted into JSON object, comprising:
Receive the JSON data that the client is sent;
According to the request type of the JSON data, interception corresponding with the request type is read from preset configuration file
Path;
The JSON data distribution is given into the corresponding blocker in the interception path, by the JSON number in the blocker
Factually example is melted into JSON object.
4. JSON data transfer device as described in claim 1, which is characterized in that be directed to the preset common java class collection
Each common java class in conjunction, the attribute-name of the common java class and the attribute-name of the JSON object are compared one by one
Compared with if all properties name of the common java class is included in the attribute-name of the JSON object, by the common java class
It is instantiated as common Java object, and by the corresponding attribute value of attribute-name identical with the common java class in the JSON object
It is assigned to the common Java object, comprising:
The attribute-name of the JSON object is added in the first array as array element;
The attribute-name of each common java class in the preset common java class set is added to as array element
In second array, and delete the attribute-name of the duplicate common java class in second array;
First array is compared with second array, if the element number of first array and second number
The element number of group is equal, and the element value of first array is equal with the element value of second array, then will be described
Common java class is instantiated as common Java object, and by attribute-name pair identical with the common java class in the JSON object
The attribute value answered is assigned to the common Java object.
5. JSON data transfer device as claimed in claim 4, which is characterized in that described by the preset common java class
The attribute-name of each common java class is added in the second array as array element in set, and deletes second number
In group after the attribute-name of the duplicate common java class, the JSON data transfer device further include:
First array is compared with second array, if the element number of first array and second number
The element number of group is unequal or the element value of first array and the element value of second array it is unequal, then it is defeated
The exception information of difference set out comprising first array and second array.
6. a kind of JSON data conversion device, which is characterized in that the JSON data conversion device, comprising:
Module is instantiated, is melted into JSON object for receiving the JSON data of client transmission, and by the JSON data instance;
Reflect value module, for using reflection mechanism, obtain the attribute-name of the JSON object, and in the JSON object
The corresponding attribute value of each attribute-name;
Value module is traversed, for traversing preset common java class set, and it is described preset general using reflection mechanism acquisition
The attribute-name of each common java class in logical java class set;
Compare assignment module, it, will be described common for being directed to each common java class in the preset common java class set
Compared with the attribute-name of java class carries out one by one with the attribute-name of the JSON object, if all properties name of the common java class
Included in the attribute-name of the JSON object, then the common java class is instantiated as common Java object, and will be described
The corresponding attribute value of identical with common java class attribute-name is assigned to the common Java object in JSON object.
7. JSON data conversion device as claimed in claim 6, which is characterized in that the JSON data conversion device is also wrapped
It includes:
The common Java object is converted by conversion module if the data acquisition request for receiving destination client
Data connection object;
Sending module, for using the data connection object by the common Java object with the data acquisition request pair
The target data answered is sent to the destination client.
8. JSON data conversion device as claimed in claim 6, which is characterized in that the instantiation module includes:
Receiving submodule, the JSON data sent for receiving the client;
Reading submodule reads from preset configuration file and asks with described for the request type according to the JSON data
Ask the corresponding interception path of type;
Matched sub-block, for the JSON data distribution to be given the corresponding blocker in the interception path, in the interception
The JSON data instance is melted into JSON object in device.
9. a kind of computer equipment, including memory, processor and storage are in the memory and can be in the processor
The computer program of upper operation, which is characterized in that the processor realized when executing the computer program as claim 1 to
The step of any one of 5 JSON data transfer device.
10. a kind of computer readable storage medium, the computer-readable recording medium storage has computer program, and feature exists
In realizing the JSON data transfer device as described in any one of claim 1 to 5 when the computer program is executed by processor
Step.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811138514.8A CN109408569A (en) | 2018-09-28 | 2018-09-28 | JSON data transfer device, device, computer equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811138514.8A CN109408569A (en) | 2018-09-28 | 2018-09-28 | JSON data transfer device, device, computer equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN109408569A true CN109408569A (en) | 2019-03-01 |
Family
ID=65466410
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811138514.8A Pending CN109408569A (en) | 2018-09-28 | 2018-09-28 | JSON data transfer device, device, computer equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109408569A (en) |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110221820A (en) * | 2019-04-23 | 2019-09-10 | 平安科技(深圳)有限公司 | The general type of spring frame relies on method for implanting, device and computer equipment, storage medium |
CN110222008A (en) * | 2019-05-06 | 2019-09-10 | 平安国际智慧城市科技股份有限公司 | A kind of conversion method of data format, system, medium and electronic equipment |
CN110278331A (en) * | 2019-06-26 | 2019-09-24 | Oppo广东移动通信有限公司 | Feedback method, device, terminal and the storage medium of system property |
CN111045685A (en) * | 2019-11-05 | 2020-04-21 | 贝壳技术有限公司 | Code conversion method, device, storage medium and electronic equipment |
CN111290808A (en) * | 2020-01-13 | 2020-06-16 | 中国平安财产保险股份有限公司 | Product module display method and device based on data transmission object and storage medium |
CN111581267A (en) * | 2020-04-14 | 2020-08-25 | 北京明略软件***有限公司 | Object data storage method and device |
CN111680475A (en) * | 2020-04-28 | 2020-09-18 | 五八有限公司 | Data conversion method and device, electronic equipment and storage medium |
CN111753499A (en) * | 2020-07-07 | 2020-10-09 | 江苏中威科技软件***有限公司 | Method for merging and displaying electronic form and OFD format file and generating directory |
CN112433787A (en) * | 2020-11-09 | 2021-03-02 | 北京达佳互联信息技术有限公司 | Target object serialization method and device, electronic device and storage medium |
CN113468866A (en) * | 2021-06-30 | 2021-10-01 | 建信金融科技有限责任公司 | Method and device for analyzing non-standard JSON string |
CN114860413A (en) * | 2022-05-25 | 2022-08-05 | 苏州浪潮智能科技有限公司 | Processing method and system for converting JAVA into JSON |
CN115686459A (en) * | 2022-10-31 | 2023-02-03 | 北京力控元通科技有限公司 | Model generation method, device and equipment based on Java language and readable storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050262041A1 (en) * | 2004-05-21 | 2005-11-24 | Bea Systems, Inc. | Systems and methods for plain old java object (POJO) persistence |
US20080301636A1 (en) * | 2007-05-31 | 2008-12-04 | Red Hat, Inc. | Per-instance and per-class aspects |
CN107222545A (en) * | 2017-06-20 | 2017-09-29 | 北京全域医疗技术有限公司 | A kind of data transmission method and device |
-
2018
- 2018-09-28 CN CN201811138514.8A patent/CN109408569A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050262041A1 (en) * | 2004-05-21 | 2005-11-24 | Bea Systems, Inc. | Systems and methods for plain old java object (POJO) persistence |
US20080301636A1 (en) * | 2007-05-31 | 2008-12-04 | Red Hat, Inc. | Per-instance and per-class aspects |
CN107222545A (en) * | 2017-06-20 | 2017-09-29 | 北京全域医疗技术有限公司 | A kind of data transmission method and device |
Non-Patent Citations (2)
Title |
---|
HAHA_SIR: "java中pojo对象和json相互转化", pages 1 - 16, Retrieved from the Internet <URL:https://blog.csdn.net/HaHa_Sir/article/details/79067209> * |
衍悔: "编写JAVA工具之json自动封装成pojo", pages 1 - 9, Retrieved from the Internet <URL:https://www.cnblogs.com/bfchuan/p/4623229.html> * |
Cited By (19)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2020215686A1 (en) * | 2019-04-23 | 2020-10-29 | 平安科技(深圳)有限公司 | Spring framework generic dependency injection method and apparatus, computer device and storage medium |
CN110221820A (en) * | 2019-04-23 | 2019-09-10 | 平安科技(深圳)有限公司 | The general type of spring frame relies on method for implanting, device and computer equipment, storage medium |
CN110221820B (en) * | 2019-04-23 | 2024-05-28 | 平安科技(深圳)有限公司 | Spring framework generalized dependency injection method and device, computer equipment and storage medium |
CN110222008A (en) * | 2019-05-06 | 2019-09-10 | 平安国际智慧城市科技股份有限公司 | A kind of conversion method of data format, system, medium and electronic equipment |
CN110278331A (en) * | 2019-06-26 | 2019-09-24 | Oppo广东移动通信有限公司 | Feedback method, device, terminal and the storage medium of system property |
CN111045685A (en) * | 2019-11-05 | 2020-04-21 | 贝壳技术有限公司 | Code conversion method, device, storage medium and electronic equipment |
CN111290808A (en) * | 2020-01-13 | 2020-06-16 | 中国平安财产保险股份有限公司 | Product module display method and device based on data transmission object and storage medium |
CN111290808B (en) * | 2020-01-13 | 2023-10-20 | 中国平安财产保险股份有限公司 | Product module display method and device based on data transmission object and storage medium |
CN111581267A (en) * | 2020-04-14 | 2020-08-25 | 北京明略软件***有限公司 | Object data storage method and device |
CN111680475A (en) * | 2020-04-28 | 2020-09-18 | 五八有限公司 | Data conversion method and device, electronic equipment and storage medium |
CN111680475B (en) * | 2020-04-28 | 2022-11-15 | 五八有限公司 | Data conversion method and device, electronic equipment and storage medium |
CN111753499A (en) * | 2020-07-07 | 2020-10-09 | 江苏中威科技软件***有限公司 | Method for merging and displaying electronic form and OFD format file and generating directory |
CN111753499B (en) * | 2020-07-07 | 2021-02-05 | 江苏中威科技软件***有限公司 | Method for merging and displaying electronic form and OFD format file and generating directory |
CN112433787A (en) * | 2020-11-09 | 2021-03-02 | 北京达佳互联信息技术有限公司 | Target object serialization method and device, electronic device and storage medium |
CN113468866A (en) * | 2021-06-30 | 2021-10-01 | 建信金融科技有限责任公司 | Method and device for analyzing non-standard JSON string |
CN113468866B (en) * | 2021-06-30 | 2022-09-16 | 建信金融科技有限责任公司 | Method and device for analyzing non-standard JSON string |
CN114860413A (en) * | 2022-05-25 | 2022-08-05 | 苏州浪潮智能科技有限公司 | Processing method and system for converting JAVA into JSON |
CN114860413B (en) * | 2022-05-25 | 2024-06-25 | 苏州浪潮智能科技有限公司 | JAVA-to-JSON processing method and system |
CN115686459A (en) * | 2022-10-31 | 2023-02-03 | 北京力控元通科技有限公司 | Model generation method, device and equipment based on Java language and readable storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109408569A (en) | JSON data transfer device, device, computer equipment and storage medium | |
US10649742B2 (en) | Computing expression medium, development environment, and device communication and control architecture | |
US9171182B2 (en) | Dynamic data masking | |
JP4991040B2 (en) | Interpreting command scripts using local and extended storage for command indexing | |
US9201920B2 (en) | Creating data in a data store using a dynamic ontology | |
US5758351A (en) | System and method for the creation and use of surrogate information system objects | |
US20120192154A1 (en) | Techniques for debugging computer programs involving multiple computing machines | |
CN106844380A (en) | A kind of database operation method, information processing method and related device | |
CN106294742A (en) | A kind of space launching site security reliability database construction method and analyzing and assessment system | |
CN109616212A (en) | Disease data processing method, device, electronic equipment and readable medium | |
CN106649457A (en) | Data processing frame based on object relation mapping technology | |
US20230344813A1 (en) | Method and system for securing asset data in a computing environment | |
CN104517181A (en) | Enterprise content management system and enterprise content management method for nuclear power plants | |
US9373093B2 (en) | Gateway service manager for business object applications | |
US10402380B1 (en) | Interactive user interface for schema transformation | |
KR101877828B1 (en) | User interface integrated platform system based on artificial intelligence | |
US20100070460A1 (en) | System and method for rule-based data object matching | |
US20190347341A1 (en) | Method and system for schema transformation | |
US7831955B2 (en) | Development and execution platform | |
CN113849492B (en) | System for providing standardized data quality check for multi-scene service | |
US20030233343A1 (en) | System and method for generating custom business reports for a WEB application | |
Paulheim et al. | Mapping pragmatic class models to reference ontologies | |
EP1646940A2 (en) | Designing computer programs | |
Lu et al. | Bigraph specification of software architecture and evolution analysis in mobile computing environment | |
Härer | Towards Interoperability of Open and Permissionless Blockchains: A Cross-Chain Query Language |
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 |