Hi everyone, maybe this is a dumb question but sup...
# serialization
c
Hi everyone, maybe this is a dumb question but suppose I do this:
Copy code
@Serializable
data class MyClass(val myProp: String, private val myPrivateProp: String)
does
myPrivateProp
get serialized?
m
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?
c
good point! thanks @Marc Knaup
I suppose I could check easily; sorry I was just reaching out for an easy answer
m
btw, data classes don’t really have private properties afaik. You could still access it using
.component2()
, can’t you? 😄
c
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
👍 1
m
(if you need
data
at all)
c
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
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
c
ok thanks for the info @Nick Johnson
👍 1
n
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..