voben
07/17/2020, 8:07 PMCasey Brooks
07/17/2020, 8:37 PMJoão Gonçalves
07/17/2020, 8:40 PMOG
07/18/2020, 4:21 AMokarm
07/18/2020, 7:55 PMnull
. Some fields just must not ever be null
, like the id
field of a domain entity. Your validator/mapper will have to cope with it.
If your backend sends you a list of entities, some of which have null
ID by mistake (remember, entity ID must never be null), what do you do then?
Do you just skip over them? - inconsistent data.
Do you block the application? - unusable app.
Do you delete cache and redirect user back to login? - user stuck in a login loop.
Making every field nullable in your API model just moves the problem elsewhere.
Some fields can be safely made not nullable at the API model level, like the aforementioned entity ID. And also many other fields, depending on your domain.
Presumably a field named username
could never be null. How could your user create an account without username
, right? So val username: String
is pretty safe.