/** * Key Value Schema using passed in schema type, support JSON and AVRO currently. */ public static <K, V> Schema<KeyValue<K, V>> of(Class<K> key, Class<V> value, SchemaType type) { checkArgument(SchemaType.JSON == type || SchemaType.AVRO == type); if (SchemaType.JSON == type) { return new KeyValueSchema<>(JSONSchema.of(key), JSONSchema.of(value)); } else { // AVRO return new KeyValueSchema<>(AvroSchema.of(key), AvroSchema.of(value)); } }
static <T> Schema<T> AVRO(Class<T> clazz) { return AvroSchema.of(clazz); }
@SuppressWarnings("unchecked") private static <T> Schema<T> newSchemaInstance(Class<T> clazz, SchemaType type) { switch (type) { case NONE: return (Schema<T>) Schema.BYTES; case AUTO_CONSUME: case AUTO: return (Schema<T>) Schema.AUTO_CONSUME(); case STRING: return (Schema<T>) Schema.STRING; case AVRO: return AvroSchema.of(clazz); case JSON: return JSONSchema.of(clazz); case PROTOBUF: return ProtobufSchema.ofGenericClass(clazz, Collections.emptyMap()); default: throw new RuntimeException("Unsupported schema type" + type); } }