title: How to fix "While parsing a protocol message, the input ended unexpectedly in the middle of a field" error
body: <p>Getting InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field. error when parsing Protobuf</p>
  
  <p>Not sure why parsing failing ever though I can see the output if I call response.getContentAsString() method on response object.</p>
  
  <p>my Proto file:</p>
  
  <pre><code>syntax = "proto2";
  package  com.test.protocol;
  
  option java_package = "com.test.protocol.v1";
  option java_outer_classname = "Test1";
  
  message Test2 {
      required int64 id                  = 1;
      required string value               = 2
  }
  </code></pre>
  
  <p>I wrote API to return the Proto response which looks like below</p>
  
  <pre><code>final Test2.Builder builder = TEST2.newBuilder();
  builder.setId(1);
  builder.setValue("1");
  return builder.build();
  </code></pre>
  
  <p>My API will return the below output</p>
  
  <pre><code>{"id": 1,"value": "1"}
  </code></pre>
  
  <p>I'm trying to call the API and parse it back to Test2 as below</p>
  
  <pre><code>import com.test.protocol.v1.Test1.Test2;
  
  final Test2 result = Test2.parseFrom(response.getContentAsByteArray());
  </code></pre>
  
  <p>getting the error in the above step If I debug and try to print response.getContentAsString(), I'm getting correct output as below but parsing is failing.</p>
  
  <pre><code>{"id": 1,"value": "1"}
  </code></pre>