Tag Archives: gson

Gson & Deserialization of Objects Containing Arrays

After my practicum team and I banged our collective heads against the wall for several hours trying to force Gson to deserialize json arrays into a collection of complex classes containing their own collections, we chose to go another route entirely. Our problem at the time was that we had blinders on and couldn’t walk away from using Javas Collections library. I came to realize today that Gson does a fantastic job of deseralizing classes with any depth of arrays so long as those json arrays are actually represented as primitive arrays in your java class.

For example: let’s say you had the following json:

[
  {
    "name":"Beagle",
    "colors":["black","white","tan"]
  },
  {
    "name":"Dalmation",
    "colors":["white","black"]
  }
]

Continue reading Gson & Deserialization of Objects Containing Arrays