return gson.toJson(images.entries.associate { it.key.code to it.value }) } fun parseImages(json: String?): Map<ImageType, String?> { val type = object : TypeToken<HashMap<Int, String>>() {}.type return gson.fromJson<…>(json, type).entries.associate { ImageType.getImageTypeByCode(it.key) to it.value } }