Title
t

turansky

03/18/2017, 3:27 PM
Is any possibility read some fields as enum values when I use
JSON.parse()
? For example:
// JSON
{
    name: “Machine #1”
    status: 1 // possible values 1,2,3,4
}

// Data class
data class Data(val name: String, val status: Status)

enum class Status {
    NORMAL(1),
    DISABLED(2),
    ....
}

// read code
JSON.parse<Data>(source)
b

bashor

03/20/2017, 11:33 AM
No typesafe way now, but we think about something like “inline" classes. Right now You can declare own external enum class.
But use it carefully
t

turansky

03/21/2017, 7:18 AM
I don't understand how external enum class will help me. JS realization where static field are numbers required?
b

bashor

03/21/2017, 12:48 PM
how external enum class will help me
In your kotlin code it will be typed but at runtime it still will be number
JS realization where static field are numbers required?
yes, if you want to use entries in Kotlin code, like
Status.NORMAL
. I’d add it anyway, since it will be safer.