Transform data class to map kotlin

Asked by At

My problem is that I need to transform a data class in kotlin to a map, because I need to work with this structure as a requirement, because this response will be used for a groovy classes and there is a post-process where there are validations iterations etc, with this map. My data class is the next (Podcast):

data class PodCast(val id: String, val type: String, val items: List<Item>, val header: Header, val cellType:String? = "")

data class Item(val type: String, val parentId: String, val parentType: String, val id: String, val action: Action, val isNew: Boolean)

data class Header(val color: String, val label: String)

data class Action(val type: String, val url: String)

I made the transformation manually, but I need a more sophisticated way to achieve this task.


1 Answers

rasilvap On Best Solutions

I have done this very simple. I got the properties of the object, just using the .properties groovy method, which gave me the object as a map.