Error in java while wrapping protocol buffer inside json generated by jackson?

I'm sending and receiving HTTP post requests by doing the following: FooJson fooJson = new FooJson(); fooJson.setName("Bob"); FooProto.Builder fooProto = FooProto.newBuilder(); // google protobuf fooProto.setColor("Blue"); fooProto.setLength(30); BarProto.Builder barProto = BarProto.newBuilder(); barProto.setWeight(65); fooProto.setBarProto(barProto); barJson.setFooProto(new String(fooProto.build().toByteArray())); List barJsonList = new ArrayList(); barJsonList.add(barJson); fooJson.setBarJsonList(barJsonList); String data = writeJson(fooJson); // wrapper for jackson JsonGenerator RequestEntity re = new ByteArrayRequestEntity(data.getBytes()); PostMethod method = new PostMethod("http://foo.net:123/path"); method.setRequestEntity(re); httpClient.executeMethod(method); On the receiving end, I parse with the following: FooJson fooJson = readJson(request.getInputStream(), FooJson.class); for (BarJson barJson : fooJson.getBarJsonList()) { FooProto fooProto = FooProto.parseFrom(barJson.getFooProto().getBytes()); } The result during parsing of the protocol buffer on the receiving end is: com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either than the input has been truncated or that an embedded message misreported its own length. Am I doing something wrong with the way I'm converting the protocol buffer to a string? How might I be able to fix this?

以上就是Error in java while wrapping protocol buffer inside json generated by jackson?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏