title: How to get typed value from GenericRecord?
body: <p>I am working with Avro and I have a <code>GenericRecord</code>. I want to extract <code>clientId</code>, <code>deviceName</code>, <code>holder</code> from it. In the Avro Schema, <code>clientId</code> is Integer, <code>deviceName</code> is String and <code>holder</code> is a Map.</p>
  
  <p><code>clientId</code> in the avro schema:</p>
  
  <pre><code>{
      "name" : "clientId",
      "type" : [ "null", "int" ],
      "doc" : "hello"
  }
  </code></pre>
  
  <p><code>deviceName</code> in the avro schema:</p>
  
  <pre><code>{
      "name" : "deviceName",
      "type" : [ "null", "string" ],
      "doc" : "test"
  }
  </code></pre>
  
  <p><code>holder</code> in the avro schema:</p>
  
  <pre><code>{
      "name" : "holder",
      "type" : {
        "type" : "map",
        "values" : "string"
      }
  }
  </code></pre>
  
  <p>My question is - what is the recommended way to retrieve a typed value, as opposed to an Object?</p>
  
  <p>In the below code, <code>payload</code> is <code>GenericRecord</code> and we can get avro schema from it. This is what I am doing right now, extracting everything as a String. But how can I just get typed value instead. Is there any way? I mean whatever the data type is there in the avro schema, I want to extract that only.</p>
  
  <pre><code>  public static void getData(GenericRecord payload) {
      String id = String.valueOf(payload.get("clientId"));
      String name = String.valueOf(payload.get("deviceName"));
  
      // not sure how to get maps here
    }
  </code></pre>
  
  <p>So I want to extract <code>clientId</code> as Integer, <code>deviceName</code> as String and <code>holder</code> as Java map <code>Map&lt;String, String&gt;</code> from <code>GenericRecord</code>? What is the best way to do that? Can we write any utility which does all the typed conversions given generic record and schema?</p>