https://kotlinlang.org logo
#announcements
Title
# announcements
m

magisu

10/30/2019, 10:32 PM
Cause in Kotlin there is no point to write event.eventSource == null test, as at Kotlin level the event.eventSource will always be non-null
k

karelpeeters

10/30/2019, 10:35 PM
I've not really used GSON, but what about trying to call
copy()
and seeing if that throws a
NullPointerException
as a workaround?
a

Anastasia Finogenova

10/30/2019, 10:45 PM
I use Gson on Android and it does throw an exception when you try to set null as a non-null field in the object. The message is basically the object is expected to be non-nullable but was null. So I would say that should be the expected behavior. I would open an issue with Gson at gitlab if it is not what is happening
m

magisu

10/30/2019, 10:47 PM
Actually I am not even sure if it is Gson issue or a SpringBoot issue.
@karelpeeters -- a copy() does the trick, but is there a more elegant way of doing so?
k

karelpeeters

10/30/2019, 10:50 PM
hashcode()
propably works too. But a real solution would have to be part of the deserializer, this really isn't Kotlins problem.
m

magisu

10/30/2019, 10:51 PM
That's true -- but how Kotlin could prevent Java code bypass Kotlin restrictions?
k

karelpeeters

10/30/2019, 10:52 PM
Well they're using reflection, and that's exactly what reflection is for: bypassing the normal safety checks.
m

magisu

10/30/2019, 11:27 PM
I see. Well, evil...
4 Views