I work with API using Retrofit. data of two types can come: First type: enter image description here

Second type

enter image description here

The problem is in the variable cover. It can be an array, and it can be boolean.

@SerializedName("cover") private boolean cover; 

two variables of the same name of even different types cannot be

And accordingly jumps out exception. How to solve this problem?

  • 2
    Make a cover Object , and then result in a Boolean / HashMap depending on the content? Disassemble into different variables? - VAndrJ
  • one
    It seems to me that this is not a boolean , but null . Happens "cover": true ? - zRrr
  • Not. this is boolean. The error just crashes: "boolean cannot be cast to type cover" - Aleksey
  • Well, you declared it as a boolean in the model, so gson is trying to cram it in. Declare, indeed, as Object , not the TypeAdapter to write ... - zRrr
  • It is possible not Object, but JsonElement. He will tell isJsonObject or isJsonPrimitive ... TypeAdapter is also a topic. - Yura Ivanov

0