Easy way to convert "org.apache.avro.generic.GenericRecord" to "java.util.Map"
Asked
Active
Viewed 6,039 times
2 Answers
7
With java 8 lambdas you can do this like
Map<String, Object> map = new HashMap<>();
genericRecord.getSchema().getFields().forEach(field ->
map.put(field.name(), genericRecord.get(field.name())));

James Conkling
- 3,235
- 2
- 25
- 37

Ville Venäläinen
- 2,444
- 1
- 15
- 11
0
Map<String, Object> values = new HashMap<>();
for (Field field : genericRecord.getSchema().getFields()) {
values.put(field.name(), genericRecord.get(field.name()));
}

Tsolak Barseghyan
- 1,048
- 11
- 16
-
This code snippet doesnt seem to handle the field of type Record !!! – Krithika Vittal Aug 24 '20 at 03:06