Systers, an AnitaB.org community
[Mentorship - Android] Use GSON's field naming policy to change field names to snake case.
Prerequisite:
- Fork and clone the project from the github repository
- Follow the documentation for successfully setting up the project
- Open Project in Android Studio
Background:
- Camel case and snake case are two styles of naming a variable
- ThisIsCamelCase
- this_is_snake_case
- The backend is written in python which follows snake case naming style
- The android client is written in Kotlin which follows camel case naming style
- Because of this difference between the projects we have to convert every single field name in each retrofit request by using the
@SerializedName()
annotation. - Instead, we can use Gson's FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES, this will automatically change the field names for us and we can remove the overused
@SerializedName()
form data classes. # Steps: - Create an instance of Gson.
- Add a
FieldNamePolicy
using thesetFieldNamingPolicy()
method ofGsonBuilder
class. - Create an instance of GsonConverterFactory using the previously created instance of Gson.
- Use the instance of GsonConverterFactory in retrofit.
You can find an example here in the Customize Your Gson Configuration section.
Resources:
- If you need help or get lost, post a response to our questions topic in our #gci stream.
Work Submission:
After successfully fixing this issue, commit and make a Pull Request. Title of PR should contain "Program:GCI"
- Commit Message Style Guide
- Sample PR structure
- Make sure to attach either screenshot or GIF of the fixed issue
Task tags
Students who completed this task
_daksha_