Closed GoogleCodeExporter closed 9 years ago
I know this doesn't directly answer the question, but would it make more sense
to
always have an array in the JSON? It seems like the data structure in your
example
makes things more difficult for both the JavaScript and Java.
I would probably try using two different beans on the Java side. Try one first
and
see if it throws a Gson exception, then try the other one. Quick and dirty,
maybe
not the best solution.
Original comment by joshuadr...@gmail.com
on 5 Apr 2010 at 12:51
I would definitely agree with your comment although I don't have any control
over the incoming JSON.
Original comment by james.st...@epochsg.com
on 5 Apr 2010 at 1:27
I think you want to create a custom JsonDeserializer<List<Category>>.
That deserializer should check whether the passed-in object is a JsonArray
(isJsonArray()) and if so, loop over the contents, converting each to a
Category using the passed-in JsonDeserializationContext.
Otherwise it should convert the lone object to a Category, also with the
JsonDeserializationContext.
Original comment by limpbizkit
on 28 Aug 2010 at 5:33
Original issue reported on code.google.com by
james.st...@epochsg.com
on 4 Apr 2010 at 3:54