antoniolg / Kotlin-for-Android-Developers

Companion App for the book

Home Page:http://antonioleiva.com/kotlin-android-developers/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ServerClasses, gson and null properties

mateuy-dev opened this issue · comments

I have a doubt about the data classes in ServerClasses.tk.
This classes are popullated using GSon. When Gson creates the classes it will use a kind of empty constructor and it will fill the properties, therefore, there might be values that are null (in case the api changes for example). Shouldn't we put default values ensure no null properties?

I don't think so 🤔 . If it can be null, the property needs to be a nullable value. I can't say it 100% sure, but if that type is one of the value types in Java (int, long, etc), it'll probably use the default value for those types. For the rest, as in Java, it'll use null.