java - GSON different value for same key -


i using gson , retrofit android project automatically parse api needed me. however, realized api contains value in can boolean or object different types of data in api.

for example

    ...         {           "media": false,         },         {           "media": {             "mp4": "http://sample.com/something.mp4", "jpg": "http://sample.com/something.jpg",          }         },     ... 

how should gson model like?

@serializedname("media") object images; 

nothing wrong using object parse. while using parsed data use instanceof check type data is.

for ex: object instanceof boolean boolean.

edit: create model class urls. :

public class urls {  @serializedname("mp4") private string mp4url;  @serializedname("jpg") private string jpgurl;  public string getmp4url() {     return mp4url; }  public string getjpgurl() {     return jpgurl; }  } 

now check

if(parsedobject instanceof urls) {     urls urls = (urls) parsedobject;     urls.getmp4url; } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -