Yaniv Sosnovsky
04/24/2021, 3:16 PM{"drinks":[{"strDrink":"Jelly Bean","strDrinkThumb":"https:\/\/<http://www.thecocktaildb.com|www.thecocktaildb.com>\/images\/media\/drink\/bglc6y1504388797.jpg","idDrink":"13775"},{"strDrink":"Turf Cocktail","strDrinkThumb":"https:\/\/<http://www.thecocktaildb.com|www.thecocktaildb.com>\/images\/media\/drink\/utypqq1441554367.jpg","idDrink":"12418"}]}
but sometimes the server returns the following:
"{"drinks":"None Found"}"
Before using kotlinx I had a custom type convertor with Gson, and that worked fine, but I’m struggling with kotlin.
I tried to create a KSerializer to try to parse the result, and return an object with an empty list if an exception is thrown, but I keep getting this exception:
java.lang.IllegalStateException: Reader has not consumed the whole input: JsonReader(source='{"drinks":"None Found"}', currentPosition=22, tokenClass=1, tokenPosition=10, offset=11)
Any ideas how to solve this? I can always return a string instead of a data class, but this is ugly AFephemient
04/24/2021, 3:35 PMephemient
04/24/2021, 3:35 PMYaniv Sosnovsky
04/24/2021, 3:36 PMYaniv Sosnovsky
04/24/2021, 3:38 PM