thiagoretondar
05/01/2019, 12:18 PMEventFrom
only exists in this context of TrackInfoDTO
. Or should I create another file only for EventFrom
?
data class TrackInfoDTO(
val url: String,
val userID: String,
val eventFrom: EventFrom,
val UTM: Map<String, Any>
) {
data class EventFrom(
val parentElementName: String,
val elementName: String,
val CTCurrent: String,
val payload: Map<String, Any>
)
}
thiagoretondar
05/01/2019, 12:20 PMUTM
and payload
can contain any key=value. Is this Map<String, Any>
the best way to do ?Mike
05/01/2019, 1:04 PMTrackInfoDTO.EventFrom
if the type gets defined. If that’s what you want…
Side note. You don’t need to put EventFrom
in its own file if its at the top-level. Kotlin supports multiple public classes in a single file.
Don’t go crazy with it, but it is helpful for defining multiple related classes in one file for easier reading.
This is a perfect example of when putting many classes in one file would make sense. All the JSON parsing data classes in one file is much easier to read than having to navigate a whole bunch of files.thiagoretondar
05/01/2019, 2:02 PMdata class TrackInfoDTO(
val url: String,
val userID: String,
val eventFrom: EventFrom,
val UTM: Map<String, Any>
)
data class EventFrom(
val parentElementName: String,
val elementName: String,
val CTCurrent: String,
val payload: Map<String, Any>
)
thiagoretondar
05/01/2019, 2:03 PMEventFrom
private (cannot be initialized outside this file)?tddmonkey
05/01/2019, 2:11 PMprivate
thiagoretondar
05/01/2019, 2:15 PMtddmonkey
05/01/2019, 2:17 PMTrackInfoDTO
has a public constructor that accepts EventFrom
- so EventFrom
isn’t really just scoped to that filetddmonkey
05/01/2019, 2:18 PMthiagoretondar
05/01/2019, 2:36 PMdata class TrackDTO(
val url: String,
val userID: String,
val eventFrom: EventFrom,
val UTM: Map<String, Any>
)
data class EventFrom private constructor(
private val parentElementName: String,
private val elementName: String,
private val CTCurrent: String,
private val payload: Map<String, Any>
)
Mike
05/01/2019, 2:45 PMthiagoretondar
05/01/2019, 7:16 PM