17

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?

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
  • The addition of these extension functions is just hideous. Why every String should be considered a potential URL and every ByteArray a potential HTTP Response? – user1942586 Sep 10 '20 at 13:17

1 Answers1

29
import okhttp3.MediaType.Companion.toMediaType
MiguelSlv
  • 14,067
  • 15
  • 102
  • 169