Android parcelable class with object typed properties

So I am currently trying to create an android app capable of displaying calendar bookings. When I retrieve the bookings I get the following JSON:

  "id": "dqflkgjkzmvjdcdfdzs56f4sd7",
  "subject": "Test Meeting",
  "start": {
    "dateTime": "2021-08-02T14:00:00.0000000",
    "timeZone": "UTC"
  "end": {
    "dateTime": "2021-08-02T14:30:00.0000000",
    "timeZone": "UTC"
  "organiser": "Kermit"

How do you cast this to a Parcelable class? I started to make the class like this:

class Booking(
    val id: String,
    val subject: String,
    val start: String, /* This */
    val end: String, /* and this has to change to an object*/
    val organiser: String,
): Parcelable

Now I still need to find the type for the start and end objects as they have properties themselves and defining it as a separate object seems unnecessary, but that might because I am used to the Angular syntax.

Any ideas on how to cast that JSON data to a Parcelable class?


Usually, you should do with the below way, this would be the better way.

defining it as a separate object seems unnecessary

At least one object is required to handle the Start & end.

data class Booking(
    var id: String?,

    var subject: String?,

    var start: TimeData?,

    var end: TimeData?,

    var organiser: String?
): Parcelable {

    data class TimeData(
        var dateTime: String?,

        var timeZone: String?
    ): Parcelable


Use JSON to Kotlin Class plugin in you android studio, it will help to generate data class from the JSON