Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonConvertor outdated, version 2+ requires different code than given in the codelab. #166

Open
arnavpraneet opened this issue Sep 8, 2024 · 1 comment

Comments

@arnavpraneet
Copy link

URL of codelab:
Codelab

In which task and step of the codelab can this issue be found?
Step 8 - Parse the JSON response with kotlinx.serialization

Describe the problem
`import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import kotlinx.serialization.json.Json
import okhttp3.MediaType

private val retrofit = Retrofit.Builder()
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.baseUrl(BASE_URL)
.build()
`

The above code snippet no longer successfully makes a working app on Android Studio, on either emulator or actual testing device.

Steps to reproduce?

  1. Follow Codelab until Step 8
  2. Try to run app
  3. Error along the lines of:

Explain: FATAL EXCEPTION: main Process: com.example.marsphotos, PID: 23147 java.lang.IllegalArgumentException: Unable to create converter for java.util.List<com.example. marsphotos. network. MarsPhoto> for method MarsApiService.getPhotos at retrofit2.Utils.methodError( Utils. java: 54) with tag AndroidRuntime

Versions
Android Studio version: Current version: Android Studio Koala | 2024.1.1 Patch 1 Al-241.18034.62.2411.12071903 July 11, 2024
API version of the emulator: 24 Nougat

Potential Solution
This StackOverflow link: https://stackoverflow.com/questions/34315499/unable-to-create-converter-for-java-util-list-retrofit-2-0-0-beta2 gives the correct code in the first answer:
String baseUrl = "" ; Retrofit client = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .build();

Additional information
Include screenshots if they would be useful in clarifying the problem.

@arnavpraneet arnavpraneet changed the title Get Data from the Internet JsonConvertor outdated, version 2+ requires different code than given in the codelab. Sep 8, 2024
@Brownie956
Copy link

By comparing the end codelab code with the Github solution code, the fix for this was to bump the plugin version of 'org.jetbrains.kotlin.plugin.serialization' from 1.8.10 up to 1.9.10.

As mentioned though, the codelab needs updating to include this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants