campyre
campyre copied to clipboard
Consider using GSON
GSON takes all the work out of dealing with json and java objects. No more manual extraction of fields.
I actually prefer the manual extraction of fields, myself. I've never liked the tightly bound Class->JSON style of GSON - I find it inflexible and annoying to deal with optional fields and changing schemas. Then again, we're tied to someone else's service whose fields are probably going to remain very static, so I guess it's not a huge deal, even if I still don't like the style.
Gson's pretty nice in that it does what you expect. Inner hashes are converted to objects, ignores transient fields, handle arrays/lists identically, and you can use @Named to convert a json name to a java name, definitely required in this schema's case. Fields in json but not in java are just ignored.
Yeah, if you were in a rapid change environment, I could see it being annoying. I guess I like using the java type hierarchy to specify everything rather than strings. But to each his own.
Most of my Android work has been done on apps where I also control the server, and so I'm constantly making changes to improve things. If you feel strongly about it being awesome, the environment here is static enough that I probably wouldn't object.