0

I am starting code refactoring for integrating four small projects to one project,the four projects is very similar. the general logic of the project is as this:a http-server to receive the request,the request is as a json format,for example A(we call A has two objects: a_key, b_key):

 {a_key : a_value, b_key : {bb_key: {b_key1 : b_value1}}}  

but the four types of request is not the same, there is a little different between them. for example: the second project receive request as this B(we call B has three objects: a_key, c_key, d_key):

 {a_key : a_value, c_key : {cc_key: {c_key1 : c_value1}},d_key: [dd1, dd2, dd3]} 

just as the above, all the requests is in JSON format, the different is "some key" may have a different name(eg: bb_key, cc_key), and the parameter count may be different(eg: B has dd_key parameter).I can't be sure the concrete parameter's names and counts. Also, all the responses are in JSON format, but as requests, a little different between them. The process is similar, according to the parameter, after some filters, the response is returned.

I think the difficult of refactoring of this is a general of Request and Response, now in our four projects, most of the code is similar, but a little different for Request and Response, our code use Java, we use Jackson to translate every request, we define a concrete class for every object in the request(eg: a_key, b_key, c_key, d_key). I don't want define so many objects class for the 4 type requests, since there is only one or two parameter different. now I have no idea to general this Request, any guy has ideas? thank you!

4

1 回答 1

0

在泛型类中,将您的 json 参数转换为 HashMap。实现工厂设计模式,工厂类将根据 HashMap 中是否存在所需的键返回适当的过滤器。使用返回的过滤器来处理您的结果并返回 JSON 响应。

于 2013-07-29T04:27:14.637 回答