@Test public void test() throws FieldMappingException { GenericRecord record = TestUtils.generateRandomAvroRecord(); AvroGenericRecordTypeMapper typeMapper = new AvroGenericRecordTypeMapper(); Object field = typeMapper.getField(record, "field1"); Assert.assertEquals(field.getClass(), String.class); }
@Override public Object getField(GenericRecord record, String fieldPath) throws FieldMappingException { if (fieldPath.equals(FIELD_PATH_ALL)) { return record; } Object field = record; try { for (String part: fieldPath.split("\\.")) { field = ((GenericRecord) field).get(part); } } catch (Exception e) { throw new FieldMappingException("Failed to retrieve fieldPath " + fieldPath + " from record " + record.toString(), e); } return field; }
AvroGenericRecordTypeMapper implements TypeMapper<GenericRecord> { @Override public Object getField(GenericRecord record, String fieldPath) throws FieldMappingException { if (fieldPath.equals(FIELD_PATH_ALL)) { return record; } Object field = record; try { for (String part: fieldPath.split("\\.")) { field = ((GenericRecord) field).get(part); } } catch (Exception e) { throw new FieldMappingException("Failed to retrieve fieldPath " + fieldPath + " from record " + record.toString(), e); } return field; } }
AvroGenericRecordTypeMapper implements TypeMapper<GenericRecord> { @Override public Object getField(GenericRecord record, String fieldPath) throws FieldMappingException { if (fieldPath.equals(FIELD_PATH_ALL)) { return record; } Object field = record; try { for (String part: fieldPath.split("\\.")) { field = ((GenericRecord) field).get(part); } } catch (Exception e) { throw new FieldMappingException("Failed to retrieve fieldPath " + fieldPath + " from record " + record.toString(), e); } return field; }  }
AvroGenericRecordTypeMapper implements TypeMapper<GenericRecord> { @Override public Object getField(GenericRecord record, String fieldPath) throws FieldMappingException { if (fieldPath.equals(FIELD_PATH_ALL)) { return record; } Object field = record; try { for (String part: fieldPath.split("\\.")) { field = ((GenericRecord) field).get(part); } } catch (Exception e) { throw new FieldMappingException("Failed to retrieve fieldPath " + fieldPath + " from record " + record.toString(), e); } return field; }  @Override Object getField(GenericRecord record, String fieldPath); }
AvroGenericRecordTypeMapper implements TypeMapper<GenericRecord> { @Override public Object getField(GenericRecord record, String fieldPath) throws FieldMappingException { if (fieldPath.equals(FIELD_PATH_ALL)) { return record; } Object field = record; try { for (String part: fieldPath.split("\\.")) { field = ((GenericRecord) field).get(part); } } catch (Exception e) { throw new FieldMappingException("Failed to retrieve fieldPath " + fieldPath + " from record " + record.toString(), e); } return field; }  @Override Object getField(GenericRecord record, String fieldPath);  }