campyre icon indicating copy to clipboard operation
campyre copied to clipboard

Consider using GSON

Open pforhan opened this issue 12 years ago • 3 comments

GSON takes all the work out of dealing with json and java objects. No more manual extraction of fields.

pforhan avatar Dec 12 '12 17:12 pforhan

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.

konklone avatar Dec 12 '12 19:12 konklone

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.

pforhan avatar Dec 12 '12 20:12 pforhan

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.

konklone avatar Dec 12 '12 21:12 konklone