30 May 2014 1min read

Don't move the problem away from the server

LinkedIn has open sourced Isaac, it's library to convert JSON into Objective-C model objects. I think it's a a cool library, although I normally use KZPropertyMapper.

But I see a problem, a big problem, in the blog post:

At LinkedIn, the mobile servers are released twice a day. Sometimes, a bug would be introduced and a value in the JSON would be a string instead of a number. Then, the method above would return an NSString instead of an NSNumber and potentially cause a crash a few lines later.

This is a thing that I see a lot while working with API's. And it's one of the reasons why I have written some posts critiquising the use of PHP (again, it's not a language problem).

I think it's a good practice avoid problems (specially crashes) in client code. We always need to protect our software against malicious input, but in cases like that I see that some people are moving the problem in an incorrect direction.

We shouldn't write libraries to protect us from bad JSON in the client, we should write libraries (or design good arquitectures) that simply make imposible to send bad JSON data throught our API.

If you enjoyed this post

Continue reading