Source:
private Object convertValue(Object deserializedObj) { Object value; if (deserializedObj instanceof IndexedRecord) { IndexedRecord indexedRecord = (IndexedRecord) deserializedObj; List<Schema.Field> fields = indexedRecord.getSchema().getFields(); Map<String, Object> keyValues = new LinkedHashMap<>(); for (Schema.Field field : fields) { keyValues.put(field.name(), convertValue(indexedRecord.get(field.pos()))); } value = keyValues; } else if (deserializedObj instanceof ByteBuffer) { ByteBuffer byteBuffer = (ByteBuffer) deserializedObj; byte[] bytes = new byte[byteBuffer.remaining()]; byteBuffer.get(bytes); value = bytes; } else if (deserializedObj instanceof GenericEnumSymbol) { GenericEnumSymbol symbol = (GenericEnumSymbol) deserializedObj; value = symbol.toString(); } else if (deserializedObj instanceof CharSequence) { value = deserializedObj.toString(); } else if (deserializedObj instanceof Map) { Map<Object, Object> map = (Map<Object, Object>) deserializedObj; Map<String, Object> keyValues = new LinkedHashMap<>(); for (Map.Entry entry : map.entrySet()) { keyValues.put(entry.getKey().toString(), convertValue(entry.getValue())); } value = keyValues; } else if (deserializedObj instanceof Collection) { Collection<Object> collection = (Collection<Object>) deserializedObj; List<Object> values = new ArrayList<>(collection.size()); for (Object obj : collection) { values.add(convertValue(obj)); } value = values; } else if (deserializedObj instanceof GenericFixed) { GenericFixed genericFixed = (GenericFixed) deserializedObj; value = genericFixed.bytes(); } else { value = deserializedObj; } return value; }

Target:
private Object convertValue(Object deserializedObj) { Object value; if (deserializedObj instanceof IndexedRecord) { IndexedRecord indexedRecord = (IndexedRecord) deserializedObj; List<Schema.Field> fields = indexedRecord.getSchema().getFields(); ImmutableMap.Builder<String, Object> keyValues = ImmutableMap.builder(); for (Schema.Field field : fields) { keyValues.put(field.name(), convertValue(indexedRecord.get(field.pos()))); } value = keyValues.build(); } else if (deserializedObj instanceof ByteBuffer) { ByteBuffer byteBuffer = (ByteBuffer) deserializedObj; byte[] bytes = new byte[byteBuffer.remaining()]; byteBuffer.get(bytes); value = bytes; } else if (deserializedObj instanceof GenericEnumSymbol) { GenericEnumSymbol symbol = (GenericEnumSymbol) deserializedObj; value = symbol.toString(); } else if (deserializedObj instanceof CharSequence) { value = deserializedObj.toString(); } else if (deserializedObj instanceof Map) { Map<Object, Object> map = (Map<Object, Object>) deserializedObj; ImmutableMap.Builder<String, Object> keyValues = ImmutableMap.builder(); for (Map.Entry entry : map.entrySet()) { keyValues.put(entry.getKey().toString(), convertValue(entry.getValue())); } value = keyValues.build(); } else if (deserializedObj instanceof Collection) { Collection<Object> collection = (Collection<Object>) deserializedObj; ImmutableList.Builder<Object> values = ImmutableList.builder(); for (Object obj : collection) { values.add(convertValue(obj)); } value = values.build(); } else if (deserializedObj instanceof GenericFixed) { GenericFixed genericFixed = (GenericFixed) deserializedObj; value = genericFixed.bytes(); } else { value = deserializedObj; } return value; }