that isn't a Kotlin-specific question. `Call` is a...
# announcements
j
that isn't a Kotlin-specific question.
Call
is a representation of the pending request and its execution mechanism (which can either be synchronous or asynchronous).
ResponseBody
is the body type, which in this case is a general wrapper around any HTTP response that will allow you to interpret it as bytes or a string or a stream.
h
okay thanks. I was wondering why my code still works if I change
ResponseBody
to
String
like this:
Copy code
@GET("notes/res")
    Call<String> getDev()
. Does that mean I wrapped the the whole HTTP response into a String?
j
Yes. But that will only work if you have a converter installed that can handle
String
. If you have a JSON converter installed it probably handles it in lenient mode. If you truly want a string representation of the HTTP response you should install the 'scalars' converter (separate artifact of Retrofit) before a JSON converter
h
okay. I think my response was being interpreted as bytes then. that explains why I couldn't do
response.body.toString()
to get my response body. But doing this sorted it out
new String(response.body.bytes())
j
You're looking for
response.body.string()
which will honor the charset defined in the content type (if any)
👍 1
h
yes that works. less code
j
feel free to ask about Retrofit and OkHttp in #C5HT9AL7Q