Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin MediaType.parse("something") is an error. moved to extension fucntion

Trying to create JSON type header for OkHttp3

val JSONtype = MediaType.parse("application/json; charset=utf-8")

But the following error is coming :

Using 'parse(String):MediaType?' is an error. moved to extension function

Shown solution/suggestion:

val JSONType = "application/json; charset=utf-8".toMediaTypeOrNull()

Do the serve the same action or requirement?

like image 246
Saswata Avatar asked Jan 29 '20 09:01

Saswata


2 Answers

Yes.

You can check out migration guide:

https://square.github.io/okhttp/upgrading_to_okhttp_4/#extension-functions

like image 181
xinaiz Avatar answered Oct 05 '22 18:10

xinaiz


Instead of

 MediaType.parse(yourString) 

use

 yourString?.toMediaTypeOrNull()
like image 40
Tarun A Avatar answered Oct 05 '22 19:10

Tarun A