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(; 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(""); 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: 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 答疑

评论 抢沙发

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

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