Should GSON ignore varying types if they're not used in a class?

Posted by loeschg on Stack Overflow See other posts from Stack Overflow or by loeschg
Published on 2014-06-10T20:31:13Z Indexed on 2014/06/10 21:25 UTC
Read the original article Hit count: 209

Filed under:
|
|
|

I'm making an API call that returns JSON which has a particular field which either returns false or a map depending on content. It's a field that I don't care about. I expected GSON to ignore this particular field, though it doesn't seem to be. The object generation fails with the following message:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 403560

I've seen this particular question (Gson deserialize json with varying value types). I want to make sure I need to make a custom deserializer before doing so. I'm wondering if I may have another issue.

edit:

Example:

"anonymous_flag": {  }

vs

"anonymous_flag": "yes"

Another Edit:

I actually had the field in my model object... I was referencing the wrong class. Judge away :)

© Stack Overflow or respective owner

Related posts about java

Related posts about android