I have records coming in ConsumerRecords for kafka consumer. I have to iterate through the ConsumerRecord and convert string(json) value to generic type object. Please help how this can be done. I don't want to use ClassName but generic type.
for (ConsumerRecord<Integer, String> cr : records) {
String str = cr.value();
Gson gson = new Gson();
ClassName dto = gson.fromJson(str, ClassName.class);
}
}
Now I did some changes and wrote the code as below which seems to work fine. Please suggest if there is any flaw in it:
for (ConsumerRecord<Integer, String> cr : records) {
String str = cr.value();
Gson gson = new Gson();
Object dto = gson.fromJson(str, Object.class);
System.out.println(dto);
}
}