how to use the new extension functions in okhttp 4
Asked Answered
P

1

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?

Problem answered 3/8, 2019 at 13:56 Comment(1)
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?Giotto
P
29
import okhttp3.MediaType.Companion.toMediaType
Problem answered 3/8, 2019 at 13:59 Comment(4)
is there auto import? Do I have to fill it out all the time?Hammerskjold
Thats the problem. CTRL + Enter wont do it for you.Problem
it's due to a bug in Kotlin IntelliJ plugin: youtrack.jetbrains.com/issue/KT-15286 supposed to be fixed in 1.3.70Moderato
Crazy that this isn't found in the okhttp docs, I was really scratching my head on their recipe page. Thank you.Subvention

© 2022 - 2024 — McMap. All rights reserved.