Case-3: If I try to case response to Message. So that I can use -> body.toByteArray(). Then I get classCaseException. Is there any way where I can convert okHttp3 httpResponse.body() to protobuf Message class On Monday, September 12, 2022 at 1:51:40 PM UTC+5:30 Dinesh Verma wrote:
> Hi, > I am writing backend service. The goal is to fetch proto-buf data from > another API, parse it and send back from my backend service. But I am > getting some exceptions. > > From another API: proto-buf message is received after sending header: > "Accept: application/x-protobuf" and json format is received after sending > header: "Accept: application/json". > > In my backend service, I have proto files and also created corresponding > java files as well. I want to return the response in proto and json as per > Accept header after calling another API. I am getting exceptions as > follows:- > > *Case-1*: As per protobuf documentation -> > <GeneratedJavaFile>.parseFrom(okHttp3 httpResponse.body.bytes()) > *Exception*: *com.google.protobuf.InvalidProtocolBufferException: While > parsing a protocol message, the input ended unexpectedly in the middle of a > field. This could mean either that the input has been truncated or that an > embedded message misreported its own length. * > *Remark: *Similar happened for inputStream as well If I try to convert > response into byteStream(). > > *Case-2:* > <GeneratedJavaFile>.Builder res = <GeneratedJavaFile>.newBuilder(); > JsonFormat.parser().merge(okHttp3 httpResponse.body.string(), res); > Exception: Then also I am getting exception. > > ---- > Kindly help as I have tried all other options available on net. Let me > know if you need any other info. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/b71e9dff-fdf6-48e6-907f-5c6f3f8240f9n%40googlegroups.com.
