PokeAPI / pokekotlin

Kotlin (or Java, Scala, etc) client for PokeApi
Apache License 2.0
171 stars 43 forks source link

JsonDataException when requesting Pokemon in Java #9

Closed alyons closed 8 years ago

alyons commented 8 years ago

I am getting a JSONDataException from com.squareup.moshi were it expects a string but it is getting a BEGIN_OBJECT.

The code I am using to make the call is as follows:

Call<Pokemon> pokemonCall = PokeApi.INSTANCE.getPokemon(nationalDexNumber);
pokemonCall.enqueue(new Callback<Pokemon>() {
    @Override
    public void onResponse(Call<Pokemon> call, retrofit2.Response<Pokemon> response) {
        Pokemon pokemon = response.body();
        for (LocationAreaEncounter encounter : pokemon.getLocation_area_encounters()) {
            ApiResource<LocationArea> areaApiResource = encounter.getLocation_area();
            areaEncounterList.add(areaApiResource.getUrl());
        }
    }

    @Override
    public void onFailure(Call<Pokemon> call, Throwable t) {
        Log.e(String.format("PokeApi.getPokemon(%d)", nationalDexNumber), "Failed to get Pokémon", t);
    }
});

Relevant Data

sargunv commented 8 years ago

Will look at it today or tomorrow.

sargunv commented 8 years ago

Fixed in v0.9.0

Let me know if you find any more issues like this. I built the data models based on the PokeApi docs, but some of it does not match up with the actual response JSON. Currently only about 60% of the API calls have been tested so there are likely others that have the same problem.