Regardless, I'd suggest just talking to the person...
# announcements
d
Regardless, I'd suggest just talking to the person who's in charge of the API to change how it responds since it's not recommended to have numeric values as property names, if possible.
Or you could do something like this
Copy code
private class ObjectPropertyAdapter : JsonDeserializer<ResponseObject>
{
    override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): ResponseObject
    {
        val jobject = json.asJsonObject
        val flattenedArray = jobject.entrySet().flatMap { (key, value) -> context.deserialize<List<ListObject>>(value, token) }
        return ResponseObject(flattenedArray)
    }

    private val token = object : TypeToken<List<ListObject>>(){}.type
}

private data class ResponseObject(val unserializableProperty : List<ListObject>)

private data class ListObject(val value : Int)
(Assuming you're using gson)
s
I was using using Gson then I swtiched to moshi, as I thought it might support this kind of structure
d
Hah, nah. You must use adapters for things like these.
s
okay i'll try out the deserializer...
can't i make an adapter using Moshi?
d
I'd assume you can. All you need to do is get object's key/value set and flatmap it.
That's really it.
s
aight
i got the api guy to change the response, thanks anyways
d
👌