I'm putting together a cheat sheet for how moshi w...
# squarelibraries
c
I'm putting together a cheat sheet for how moshi will deserialize values into your defined model depending on how your model is defined (i.e. trying to highlight, that you can have a String defined that gets a number from json, and it will indeed work/convert the number to string) So here's the silly part, when it comes to modelling a String, how many different ways could you write a field called
name
that's a String? Just 5, right? Or are there some other annotations or something that could change the result?
Copy code
val name: String = "default"
val name: String? = "default"
val name: String? = null
val name: String?
val name: String
My intent in the cheat sheet is to show "Hey if your field is defined like this, and your backend sends "foo", explicit null, or omits the field in json entirely, this is your result."