pbandk icon indicating copy to clipboard operation
pbandk copied to clipboard

Retrofit Converter

Open aminghadersohi opened this issue 5 years ago • 7 comments

Is there a recommended Convertor for Retrofit for the generated Kotlin code?

aminghadersohi avatar Jan 04 '20 01:01 aminghadersohi

@aminghadersohi We have one written internally. I'll work on getting it published as a library. It's so small that in the meantime I've put it into this gist if you want to copy it: https://gist.github.com/garyp/fe4dc73058f84245830fbae024d0ca6e.

garyp avatar Jan 06 '20 21:01 garyp

Thanks so much!

aminghadersohi avatar Jan 07 '20 05:01 aminghadersohi

Screen Shot 1398-12-27 at 1 01 59 PM

Morteza-Rastgoo avatar Mar 17 '20 09:03 Morteza-Rastgoo

Ok, That was because i was using okhttp 3 instead of 4.4.0

Morteza-Rastgoo avatar Mar 17 '20 09:03 Morteza-Rastgoo

New error: pbandk can't handle response body with content type application/x-protobuf

Morteza-Rastgoo avatar Mar 17 '20 09:03 Morteza-Rastgoo

I added this: private const val protobufxMediaType = "application/x-protobuf"

protobufMediaType, protobufxMediaType -> value.byteStream().use {
                val value =
                    messageCompanion.protoUnmarshal(Unmarshaller(CodedInputStream.newInstance(it)))
                if (BuildConfig.DEBUG) {
                    Log.d("ProtoConverter", value.toString())
                }
                value
            }

Also I want to log the request and response body, so I use value.tostring() there.

Morteza-Rastgoo avatar Mar 17 '20 10:03 Morteza-Rastgoo

Is it ok if i make it a library?

Morteza-Rastgoo avatar Mar 17 '20 12:03 Morteza-Rastgoo