title: google.protobuf.Any field with grpc is always nil
body: <p>I am using gRPC with golang. I have a very simple proto definition and a gRPC service. The proto definition has a field in Endorsement of type <em>google/protobuf/any</em>. gRPC service is unable to map this field to input value and it's always getting initialised to nil</p>
  <p><strong>proto definition</strong>:</p>
  <pre><code>syntax = &quot;proto3&quot;;
  
  option go_package = &quot;service&quot;;
  option java_multiple_files = true;
  option java_package = &quot;io.grpc.consensus&quot;;
  
  import &quot;google/protobuf/any.proto&quot;;
  
  package service;
  
  service MyService {
    rpc Verify (Payload) returns (Response) {}
  }
  
  message Response {
    string policyId =1;
    string txnId =2;
  }
  
  message Endorsement {
    string endorserId=1;
    // This is being initialise to nil by gRPC
    google.protobuf.Any data = 2;
    string signature=3;
    bool isVerified=4;
  }
  
  
  message Payload {
    string policyId =1;
    string txnId =2;
    repeated Endorsement endorsements=3;
  }
  </code></pre>
  <p>Using this, a simple gRPC service is implemented:</p>
  <pre><code>package service
  
  import (
      &quot;log&quot;
  
      &quot;golang.org/x/net/context&quot;
  )
  
  type ServiceServerImpl struct {
  }
  
  func NewServiceServerImpl() *ServiceServerImpl {
      return &amp;ServiceServerImpl{}
  }
  
  func (s *ServiceServerImpl) Verify(ctx context.Context, txnPayload *Payload) (*Response, error) {
      log.Printf(&quot;Got verification request: %s&quot;, txnPayload.TxnId)
      for _, endorsement := range txnPayload.Endorsements {
          j, err := endorsement.Data.UnmarshalNew()
          if err != nil {
              log.Print(&quot;Error while unmarshaling the endorsement&quot;)
          }
          if j==nil {
         //This gets printed as payload's endorsement data is always null for google/protobuf/any type
              log.Print(&quot;Data is null for endorsement&quot;)
          }
      }
      return &amp;Response{TxnId: txnPayload.TxnId,  PolicyId: txnPayload.PolicyId}, nil
  }
  </code></pre>
  <p><strong>Input Data:</strong></p>
  <pre><code>{
    &quot;policyId&quot;: &quot;9dd97b1e-b76f-4c49-b067-22143c954e75&quot;,
    &quot;txnId&quot;: &quot;231-4dc0-8e54-58231df6f0ce&quot;,
    &quot;endorsements&quot;: [
      {
        &quot;endorserId&quot;: &quot;67e1dfbd-1716-4d91-94ec-83dde64e4b80&quot;,
        &quot;data&quot;: {
          &quot;type&quot;: &quot;issueTx&quot;,
          &quot;userId&quot;: 1,
          &quot;transaction&quot;: {
              &quot;amount&quot;: 10123.50
          }
      },
        &quot;signature&quot;: &quot;MEUCIBkooxG2uFZeSEeaf5Xh5hWLxcKGMxCZzfnPshOh22y2AiEAwVLAaGhccUv8UhgC291qNWtxrGawX2pPsI7UUA/7QLM=&quot;,
        &quot;isVerified&quot;: false
      }
    ]
  }
  </code></pre>
  <p>Client:</p>
  <pre><code>type Data struct {
      Type        string      `json:&quot;type&quot;`
      UserId      int16       `json:&quot;userId&quot;`
      Transaction Transaction `json:&quot;transaction&quot;`
  }
  
  type Transaction struct {
      Amount float32 `json:&quot;amount&quot;`
  }
  
  data := &amp;Data{Type: &quot;Buffer&quot;, UserId: 1, Transaction: Transaction{Amount: 10123.50}}
      byteData, err := json.Marshal(data)
      if err != nil {
          log.Printf(&quot;Could not convert data input to bytes&quot;)
      }
  
      e := &amp;any.Any{
          TypeUrl: &quot;anything&quot;,
          Value:   byteData,
      }
  
      endosement := &amp;Endorsement{EndorserId: &quot;1&quot;, Signature: &quot;MEUCIBkooxG2uFZeSEeaf5Xh5hWLxcKGMxCZzfnPshOh22y2AiEAwVLAaGhccUv8UhgC291qNWtxrGawX2pPsI7UUA/7QLM=&quot;, Data: e, IsVerified: false}
      var endosements = make([]*Endorsement, 1)
      endosements[0] = endosement
      t := &amp;Payload{TxnId: &quot;123&quot;, PolicyId: &quot;456&quot;, Endorsements: endosements}
  
      response, err := c.Verify(context.Background(), t)
      if err != nil {
          log.Fatalf(&quot;Error when calling SayHello: %s&quot;, err)
      }
  </code></pre>
  <p>How should <em>google/protobuf/any</em> type be Unmarshal for unknown types?</p>
  <pre><code>m, err := e.Data.UnmarshalNew()
      if err != nil {
          log.Print(&quot;Error while unmarshaling the endorsement&quot;)
      }
  </code></pre>
  <blockquote>
  <p>throws an error: s:&quot;not found&quot;</p>
  </blockquote>