there:
Our app uses JSON to talk to the backend server. And as time goes by, the amount of APIs are growing dramatically. For each new API that is added, or an existing API modified, I have to go through the following tedious process so far
- abstract an class properties into a class to fit into the logic model
- implement a construction of the request dictionary, serialize it and send
- for the responses, I deserialize them, and then look at the response definition(schema), and unpack them.
As you can imagine, for some complex APIs, where values that are again recursive dictionaries, it's extremely error prone and annoying to construct and parse...
After a while, I found that there's a software Objectify which creates code for JSON. For response parsing, it's working for me(even though, I have trouble mapping the code it generates using properties into my object model, which differs). But it's working for my requirements to some extent -- I can eliminate half of the tedious work.
However, I found my self stuck with Objectify. So my question is, if you know any way to "automatically construct the JSON request", using either iOS build-in tools, or external libs?
The tool Objectify actually parses JSON data/schema, and generates code with a bunck of properties and 2 functions which unpacks data into dictionary. After some thinking, I think it's not possible for this tool to do that.
If there's no existing way(which I think it's very difficult, since, no way to know and construct the requests dictionaries automatically -- there could be same key in an outer level and an internal level). I am now thinking about declaring a property, and force all new APIs and implementor to implement their own (Dictionary *)constructRequest method.
Anyone faced this problem before, any suggestions?
Thanks in advance!