Basically I am calling a Server and expect a JSON response. The complication is when I need to pass the parameter which is in the form of JSON. The initial outcome of my thought process was to have a file that has the JSON input and can be modified according to the individual commands.

This approach is cumbersome for the end user as it has to tweak many values in JSON, so the initial research fails.

Here I am in midst of either creating a wrapper that generates the JSON to be sent, around the current application which takes JSON as an input file. So the logic remains the same but the wrapper processes the input and creates a input file which is internally given to the existing application.

But again the problem lies in "How can you create Wrapper that creates the JSON". Isn't it the same old logic ?

My possible parameters expected by server changes with each command.

Any design pattern is suggested here ? Please let me know in case of further explanation is required.

  • 1
    It'd be handy to know what kind of data you need to post. e.g. do you have large amounts of nested arrays. As well if you could give some context into how the user will be thinking about this data would be helpful - it's still a UI after all. – Dar Brett Feb 20 '17 at 14:00
  • see Choosing the right Design Pattern – gnat Feb 20 '17 at 14:51
  • @DarBrett Yes It's a collection of nested arrays. Plus every field is mandatory for user. – DevMac Feb 21 '17 at 5:41

Honestly, I am having a tough time understanding what needs to be done. When you say the server needs to be passed a parameter that is in the form of JSON, what I think you mean is the server REST API expects you to POST a request to a URL with a JSON that has the "parameters". This is probably what you mean, and makes sense because that is how a lot of APIs work.

For example, a site that allows uploading user objects into its database via a REST API might have a URL http://myapp.mycompany.com/user/put and expects that URL to be called with an http POST with a JSON representation of a user object.

The best way to go about this is to find where you GET the object from that same API, because that will spit out a JSON example of an object. Use that JSON to generate a POJO. There are many automated ways of going about this, and a few sites that provide a generator that you upload the JSON and it gives back the POJOs which are structured to match the JSON format.

Then you use something like google gson (my preferecne, there are others) which can translate your POJO into a json object which you use in your http POST, or ingest into your app -- via the POJO you created to match the JSON.

This all sounds involved and time consuming, but really isn't.

  • I should have mentioned that once you have your POJOs generated, using google gson to serialize/deserialize an object to/from JSON is one line. I also should have paid more attention that the question was not asked specific to java, and my answer is. I am sure that whatever language is being used, it will have a way of going about this similarly. – Thomas Carlisle Feb 20 '17 at 17:37
  • The language used is C++ and yes it's quite generic and handy – DevMac Feb 21 '17 at 5:44
  • I think Python would be a nice fit for this problem, isn't' it @Thomas – DevMac Feb 21 '17 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.