‫We added the dependency of Json converter library.
‫But why we need this converter?
‫The Json converter is a component of retrofit.
‫It's responsible for converting Json data from the network response into Kotlin or Java objects, and
‫vice versa in retrofit.
‫You typically configure the Json converter as part of your retrofit instance.
‫So Json converter used to convert Java objects into their Json representation.
‫It can also be used to convert a Json string to an equivalent Java object.
‫Think about Json converters used for serialization and deserialization of Json response.
‫Json provides several built in Serializers and Deserializers as serializer allows to convert a Json
‫string to corresponding Java type, a Deserializer allows to convert from Java to Json representation.
‫We're going to serialize at first, because we need to get the response from the Json into Kotlin or
‫Java objects.
‫Back to our question model class.
‫We use this annotation serialized name and this annotation expose.
‫At first, let me discuss the serialized name and serialized name.
‫Annotation is an annotation provided by the Json library.
‫It's used to map Java or Kotlin objects fields to the key or field names in Json data.
‫When you receive Json data from an API like this response, the keys in the Json may not always match
‫the variable names you want to use in your Java class.
‫So for example, here we have the string question.
‫If I name it as question body.
‫For example, this is the variable question body.
‫This question body is not matching the key question.
‫So at serialized name annotation allows you to specify the mapping between the Json key and the objects
‫field.
‫Here I'm telling this question body is similar to the question key in the API response.
‫My advice to you is to create the same variable name as the keys and as the columns in the database.
‫So here we have the key question option one, option two, option three, option four, and correct
‫underscore option for that.
‫In order to prevent any possible error, just use the same variable names as the key names.
‫Question is similar to question option one is similar to option one and so on.
‫Here I want from you to focus correct underscore option is different from correct option.
‫So add serialized name should be annotation should be added.
‫For example if we look at option four it's similar to option for key here.
‫So option four I can get rid of serialized name annotation.
‫So I can remove serialized name because option four is matching option for key in the Json response,
‫but the correct option is not matching correct option here in the key.
‫So I need to add at serialized name annotation, and I'll specify the correct option inside the serialized
‫name annotation.
‫Here I'm referencing.
‫This correct option is linked and mapping this correct option variable to this key.
‫Correct underscore option key.
‫Again guys, whenever you have similar variables, there is no need to use at serialized name.
‫But for better implementation and to provide any possible error, please keep the serialized name and
‫notation.
‫Now let's move to add, expose and notation.
‫Add, expose and notation is also a Json annotation, but it's used for controlling field serialization
‫and deserialization behavior by default.
‫Jason, Serializes and Deserializes all fields of a class, but if you want to exclude specific fields
‫from serialization or deserialization, you can use Add expose annotation.
‫To use Add expose annotation, you need to configure your Json instance to honor it, and you do it
‫by creating a Json instance with a Json builder and configuring it to exclude fields annotated with
‫expose.
‫So I can use dot exclude fields without expose annotation method in the Json builder, but I'll not
‫use it in this application just to inform you and to tell you about the add serialized name annotation
‫and add Expose annotation so you can exclude them from deserialization or serialization.
‫We learned about this Json converter.
‫We learned about expose annotation and serialized name.
‫Now let's move to create other retrofit parts.