Chris Fillmore

    Chris Fillmore

    2 years ago
    Hi everyone, maybe this is a dumb question but suppose I do this:
    @Serializable
    data class MyClass(val myProp: String, private val myPrivateProp: String)
    does
    myPrivateProp
    get serialized?
    m

    Marc Knaup

    2 years ago
    My guess is that it will, otherwise how would you create a new instance during deserialization if there is no value available for that constructor parameter?
    Chris Fillmore

    Chris Fillmore

    2 years ago
    good point! thanks @Marc Knaup
    I suppose I could check easily; sorry I was just reaching out for an easy answer
    m

    Marc Knaup

    2 years ago
    btw, data classes don’t really have private properties afaik. You could still access it using
    .component2()
    , can’t you? 😄
    Chris Fillmore

    Chris Fillmore

    2 years ago
    makes sense. I was in a situation last night where I have several similar-but-not-identical requests going out as json, and wanted to share some of the field definitions between them
    this turned out to be a mess. So instead I just have a bit of duplication across my data classes
    m

    Marc Knaup

    2 years ago
    (if you need
    data
    at all)
    Chris Fillmore

    Chris Fillmore

    2 years ago
    Yeah I considered that too
    I figure it’s probably not a big deal one way or the other. Time will tell if it makes any difference
    thanks for the feedback
    n

    Nick Johnson

    2 years ago
    The serialization plugin will also generate custom code in a companion object to serialize and deserialize, meaning that it can have private access since it is inside the same class
    Chris Fillmore

    Chris Fillmore

    2 years ago
    ok thanks for the info @Nick Johnson
    Nikky

    Nikky

    2 years ago
    imo its not like being able to access stuff via component .. there is loads of other ways to hack visibility modifiers away.. this is all just to make it easier for developers to see that something should not be accessible..