android – Kotlin MediaType.parse("something") is an error. moved to extension fucntion-ThrowExceptions

Exception or error:

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?

How to solve:

Yes.

You can check out migration guide:

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

Leave a Reply

Your email address will not be published. Required fields are marked *