### Question:
ObjectDeserializer { public List<Object> translateRecord(Object obj) throws NoSuchFieldException, IllegalAccessException { return flattenRecord(obj, fieldNames, fieldTypes, schema); } ObjectDeserializer(Properties properties, Schema schema);  ObjectDeserializer(Properties properties, Schema schema, int fieldOffset);  ObjectDeserializer(List<String> fieldNames, List<TypeInfo> fieldTypes, Schema schema); @VisibleForTesting  ObjectDeserializer(List<String> fieldNames, List<TypeInfo> fieldTypes, Schema schema, int fieldOffset); ObjectInspector getInspector(); Object deserialize(Object obj); List<Object> translateRecord(Object obj);  }### Answer:
@Test public void testFlattenSimpleRecord() throws Exception { SimpleRecord simpleRecord = new SimpleRecord(new URI("http: HiveSimpleRecord hiveSimpleRecord = new HiveSimpleRecord(simpleRecord); List<String> fieldNames = HiveSimpleRecord.getFieldNames(); List<TypeInfo> fieldTypes = HiveSimpleRecord.getFieldTypes(); List<Object> expected = hiveSimpleRecord.getAsList(); ObjectDeserializer translator = new ObjectDeserializer(fieldNames, fieldTypes, schemaGenerator.generate(SimpleRecord.class)); List<Object> translated = translator.translateRecord(simpleRecord); assertSimpleRecordEquals(expected, translated); }
@Test public void testFlattenSimpleStructuredRecord() throws Exception { SimpleRecord simpleRecord = new SimpleRecord(new URI("http: Schema schema = new ReflectionSchemaGenerator().generate(SimpleRecord.class); StructuredRecord structuredRecord = StructuredRecord.builder(schema) .set("booleanField", simpleRecord.booleanField) .set("byteField", simpleRecord.byteField) .set("charField", simpleRecord.charField) .set("shortField", simpleRecord.shortField) .set("intField", simpleRecord.intField) .set("longField", simpleRecord.longField) .set("floatField", simpleRecord.floatField) .set("doubleField", simpleRecord.doubleField) .set("stringField", simpleRecord.stringField) .set("bytesField", simpleRecord.bytesField) .set("byteBufferField", simpleRecord.byteBufferField) .set("uuidField", simpleRecord.uuidField) .set("uriField", simpleRecord.uriField) .set("urlField", simpleRecord.urlField) .set("intsField", simpleRecord.intsField) .build(); HiveSimpleRecord hiveSimpleRecord = new HiveSimpleRecord(simpleRecord); List<String> fieldNames = HiveSimpleRecord.getFieldNames(); List<TypeInfo> fieldTypes = HiveSimpleRecord.getFieldTypes(); List<Object> expected = hiveSimpleRecord.getAsList(); ObjectDeserializer translator = new ObjectDeserializer(fieldNames, fieldTypes, schemaGenerator.generate(SimpleRecord.class)); List<Object> translated = translator.translateRecord(structuredRecord); assertSimpleRecordEquals(expected, translated); }
@SuppressWarnings("unchecked") @Test public void testNestedRecord() throws Exception { NestedRecord nestedRecord = new NestedRecord(); ObjectDeserializer translator = new ObjectDeserializer( NestedRecord.getFieldNames(), NestedRecord.getFieldTypes(), schemaGenerator.generate(NestedRecord.class)); List<Object> translated = translator.translateRecord(nestedRecord); List<Object> expected = nestedRecord.getAsList(); Assert.assertEquals(expected.get(0), translated.get(0)); Assert.assertEquals(expected.get(1), translated.get(1)); assertSimpleRecordEquals((List<Object>) expected.get(2), (List<Object>) translated.get(2)); }