I work with Avro and I have a GenericRecord . I want to extract clientId , deviceName , holder from it. In the Avro scheme, clientId is Integer, deviceName is a string, and holder is a card.
clientId in avro schema:
{ "name" : "clientId", "type" : [ "null", "int" ], "doc" : "hello" }
deviceName in the avro schema:
{ "name" : "deviceName", "type" : [ "null", "string" ], "doc" : "test" }
holder in avro schema:
{ "name" : "holder", "type" : { "type" : "map", "values" : "string" } }
My question is: what is the recommended way to get a typed value, as opposed to an object?
The payload code below has a GenericRecord , and we can get the avro scheme from it. This is what I am doing right now, fetching everything as a string. But how can I get only a typed value. Is there anyway? I mean, what type of data is present in the avro scheme, I want to extract only this.
public static void getData(GenericRecord payload) { String id = String.valueOf(payload.get("clientId")); String name = String.valueOf(payload.get("deviceName"));
So, I want to extract clientId as Integer, deviceName as String and holder as Java Map<String, String> from GenericRecord ? What is the best way to do this? Can we write any utility that performs all the typed conversions defined by the common notation and schema?