Skip to content

Commit

Permalink
Add a quick fix of parsing response model by Gson issue
Browse files Browse the repository at this point in the history
Gson issue google/gson#1107
  • Loading branch information
AlexanderKozubets committed Feb 24, 2019
1 parent 0cef155 commit 3e5664c
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package co.techmagic.hr.data.entity.time_tracker
import co.techmagic.hr.data.entity.HolidayDate
import com.google.gson.Gson
import com.google.gson.TypeAdapter
import com.google.gson.internal.LinkedTreeMap
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonToken
import com.google.gson.stream.JsonWriter
import java.text.SimpleDateFormat
import java.util.*


class UserReportsResponseTypeAdapter : TypeAdapter<UserReportsResponse>() {
Expand Down Expand Up @@ -35,7 +38,27 @@ class UserReportsResponseTypeAdapter : TypeAdapter<UserReportsResponse>() {
"firstName" -> first = reader.nextString()
"lastName" -> last = reader.nextString()
"submitted" -> submitted = reader.nextBoolean()
"reports" -> reports = readList(reader)
"reports" -> {
// FIXME: returns list of LinkedTreeMap items instead of UserReport
// See https://github.com/google/gson/issues/1107
// return readList(reader)
val list: List<LinkedTreeMap<String, Any>> = readList(reader)
val mappedList = list.map {
UserReport(
it["_id"] as String,
ReportName((it["_task"] as LinkedTreeMap<*, *>)["name"] as String),
(it["hours"] as Double).toInt(),
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(it["date"] as String),
it["lockDate"] as Boolean,
it["note"] as String,
it["status"] as String,
it["client"] as String,
it["project"] as String,
it["weekReportId"] as String
)
}
reports = mappedList
}
"holidays" -> holidays = readList(reader)
"weeksId" -> weeksId = readList(reader)
}
Expand Down

0 comments on commit 3e5664c

Please sign in to comment.