https://kotlinlang.org logo
#serialization
Title
# serialization
n

Nikky

11/02/2018, 10:42 AM
so with 0.9.0 i cannot longer just rely on implicit reflection and use
JSON.stringify(something)
for now i solved it like this
Copy code
data class Something(
    val someProperty: String
) {
    @Serializer(forClass=Something::class)
    companion object
}

JSON.parse(Something, string)
is there a better way than adding companion objects to everything ?
s

sandwwraith

11/02/2018, 11:43 AM
Is
JSON.parse(Something.serializer(), string)
working for you? Underlying mechanisms for implicit serializers were not changed, experimental annotation was added to emphasise consequences of theirs usage
n

Nikky

11/02/2018, 11:59 AM
yes it works but then i have to annotate the method, then all methods using that and eventuallz i might as well enable it globally and get no benefit from the annotation
s

sandwwraith

11/02/2018, 12:01 PM
you can use non-propagating annotation
@UseExperimental
n

Nikky

11/02/2018, 12:01 PM
what i'd like to see is that
@Serializable
automaticallz adds Serializer to the companion object if it does not exist
s

sandwwraith

11/02/2018, 12:02 PM
Yes, it does.
@Serializable
adds a companion object and function
.serializer()
on it to retrieve serializer
n

Nikky

11/02/2018, 12:02 PM
nice to know.. i already converted all my code to not use ImplicitReflection
ohh i see now
3 Views