0

Response 1:

               {
                    "id": "85",
                    "email": "jack@test.com",
                    "profession": [
                        {
                            "category_id": "1",
                            "name": "ARTIST"
                        }
                    ],
                    "genre": [
                        {
                            "category_id": "3",
                            "name": "ROCK"
                        }
                    ],
                    "instruments": "No list has found",
               }

Response 2:

  {
    "id": "85",
    "email": "jack@test.com",
    "profession": [{
        "category_id": "1",
        "name": "ARTIST"
    }],
    "genre": [{
        "category_id": "3",
        "name": "ROCK"
    }],
    "instruments": [{
        "category_id": "3",
        "name": "ROCK"
    }],
  }

In first response instruments key have a String value, In second response instruments have a array. create the pojo class for second response but some times i got first response also it move OnFailure . how can i handle in Retrofit.

KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133

1 Answers1

1

Different types of json objects is not possible to parse in single request/response. So you should use this on following way.

if your instruments object is empty means don't set string like "No list has found", Instead of you should send like "instruments": [],

now instruments is list coming but size is 0(zero), that means there is no data, like "No list has found"

so your response should be like this

{
    "id": "85",
    "email": "jack@test.com",
    "profession": [{
        "category_id": "1",
        "name": "ARTIST"
    }],
    "genre": [{
        "category_id": "3",
        "name": "ROCK"
    }],
    "instruments": [],
  "other": [{
        "category_id": "4",
        "name": "Test"
    }],
  }

Validate the list size in local and process your way..

Hope this will help you :)...

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Raja
  • 2,775
  • 2
  • 19
  • 31