Return empty list on empty value

This commit is contained in:
Naveen 2023-09-28 23:32:56 +05:30
parent 9f8d59f0d4
commit 106552036e
No known key found for this signature in database
GPG Key ID: 0E155DAD31671DA3
1 changed files with 5 additions and 1 deletions

View File

@ -29,10 +29,14 @@ class Converters {
fun stringListToJson(list: List<String>) = gson.toJson(list) fun stringListToJson(list: List<String>) = gson.toJson(list)
@TypeConverter @TypeConverter
fun attendeeListToJson(list: List<Attendee>) = gson.toJson(list) fun attendeeListToJson(list: List<Attendee>): String = gson.toJson(list)
@TypeConverter @TypeConverter
fun jsonToAttendeeList(value: String): List<Attendee> { fun jsonToAttendeeList(value: String): List<Attendee> {
if (value.isEmpty()) {
return emptyList()
}
return try { return try {
gson.fromJson<ArrayList<Attendee>>(value, attendeeType) ?: ArrayList() gson.fromJson<ArrayList<Attendee>>(value, attendeeType) ?: ArrayList()
} catch (e: Exception) { } catch (e: Exception) {