Monthly Archives: August 2014

Reflection and JSON parsing

One of the things I most hate to do in programming is parsing JSON. Not because it’s hard, but because it’s trivial. That’s the problem- it’s boring yet very time consuming. I don’t want to have to write the line myvar = jsonValue.getInt(“myvarname”,0); 1000 times. I want to take a string and just suck it up into an object. Nowdays in Java I would just use GSON, a library by Google that uses reflection to do this and is used widely by the Java community. But there was a time before this library became popular and I actually had the same idea. Since I rarely used reflection (and still rarely use it, I find it’s generally a code smell) I thought it would be a great opportunity to learn. So here it is- my own personal JSON parsing library.

As an aside- I had originally planned on revisiting this code and expanding it for a part 2 on this, but I’ve decided there’s no value here over using GSON. So I’ll take some of the features I planned to add and use them elsewhere in the future, in a bit of a broader way. As a result this update is going to be lower in detail and more in code, since I have no interest in keeping this library updated and will be moving my libraries that depend on it to GSON. I’m posting this mainly to increase my ready to go post count and to provide an interesting example into using reflection.

Continue reading