apollo-kotlin: Object with all null fields drops e: Cannot be cast to non-null type kotlin.String
Summary If I receive the object with all nullable fields as null apollo drops NullPointException, cannot be cast to non-null type kotlin.String
Version Version 3.1.0
Description
For instance I have object which contains three nullable strings. If I receive object like this:
"featuredTag": { "title": null, "slug": null, "color": null },
Apollo drops the exception. All fields inside are nullable. I was debugging line by line and noticed that exception occurs during the emit of flow. I know in perfect word I should receive object featuredTag
as null and then everything works, but sometimes from some reason our API returns as above and our app is not able to parse the response.
Thank you for any help, Cheers
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (9 by maintainers)
Hello, I found that I got error from cacheKeyGenerator in my ContentfulCacheModule. When cache key is null on response payload, my cache key get error. I think it is solved. I will let you know again after testing.
@martinbonnin I am facing same issue that in schema,we have a field as below
tags:[String!]
but During parsing Json from Response we get 2 different scenario 1-tags:null working fine during parsing from Apollo 2- tags:[ ] fails on StringAdapter() file during parsing
As we know ! denotes that it will not be null elements like
tags:[null,"element1",null,"element2"]
.So 2nd option should also works fine. Empty Array should be easliy parsed an emptyList().
Thanks! We’ll look into that!