Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use the new extension functions in okhttp 4

Hi got this compile error when upgrading from okHttp version 3 to version 4:

val JSON = MediaType.parse("application/json; charset=utf-8")
//Compile Error: Kotlin: Using 'parse(String): MediaType?' is an error. moved to extension function

I changed the call to invoke the extension method as the error points but the method is not recognizes as an String extension.

Here is how i did changed it:

val JSON = "application/json; charset=utf-8".toMediaType()

Adding the import for Companion Objects as posted in tutorial also didn't solve it:

import okhttp3.CipherSuite.Companion.forJavaName

What did i miss here?

like image 549
MiguelSlv Avatar asked Aug 03 '19 13:08

MiguelSlv


1 Answers

import okhttp3.MediaType.Companion.toMediaType
like image 152
MiguelSlv Avatar answered Nov 19 '22 00:11

MiguelSlv