Android Networking: Beyond the Basics

Sep 8 2022 · Kotlin 1.7.10, Android 12, Android Studio Chipmunk

Part 1: Implement Advanced Retrofit

02. Use Different Parsers

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 01. Introduction Next episode: 03. Implement Logging Interceptors & Error Handling

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

There are many different parsers, and each is good at what it does, in different ways. For this reason, you’ll learn how to parse data using Kotlin Serialization.

Demo

Kotlin serialization has a few different steps to integrate it into your project. Head over to the project-level build.gradle and add the following code:

classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
apply plugin: 'kotlinx-serialization'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3"
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0'
import okhttp3.MediaType.Companion.toMediaType
val contentType = "application/json".toMediaType()
val json = Json {
  ignoreUnknownKeys = true
}
...

.addConverterFactory(json.asConverterFactory(contentType))
@Serializable