Is any possibility read some fields as enum values...
# javascript
t
Is any possibility read some fields as enum values when I use
JSON.parse()
? For example:
Copy code
// 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
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
I don't understand how external enum class will help me. JS realization where static field are numbers required?
b
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.