public static <T extends com.google.protobuf.GeneratedMessageV3> ProtobufSchema<T> of( Class<T> pojo, Map<String, String> properties){ return ofGenericClass(pojo, properties); } }
public static ProtobufSchema ofGenericClass(Class pojo, Map<String, String> properties) { if (!com.google.protobuf.GeneratedMessageV3.class.isAssignableFrom(pojo)) { throw new IllegalArgumentException(com.google.protobuf.GeneratedMessageV3.class.getName() + " is not assignable from " + pojo.getName()); } return new ProtobufSchema<>(properties, pojo); }
public static <T extends com.google.protobuf.GeneratedMessageV3> ProtobufSchema<T> of(Class<T> pojo) { return of(pojo, Collections.emptyMap()); }
private ProtobufSchema(Map<String, String> properties, Class<T> pojo) { try { T protoMessageInstance = (T) pojo.getMethod("getDefaultInstance").invoke(null); tParser = (Parser<T>) protoMessageInstance.getParserForType(); this.schemaInfo = new SchemaInfo(); this.schemaInfo.setName(""); Map<String, String> allProperties = new HashMap<>(); allProperties.putAll(properties); // set protobuf parsing info allProperties.put(PARSING_INFO_PROPERTY, getParsingInfo(protoMessageInstance)); this.schemaInfo.setProperties(allProperties); this.schemaInfo.setType(SchemaType.PROTOBUF); ProtobufDatumReader datumReader = new ProtobufDatumReader(pojo); org.apache.avro.Schema schema = datumReader.getSchema(); this.schemaInfo.setSchema(schema.toString().getBytes()); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IllegalArgumentException(e); } }
private ProtobufSchema(Map<String, String> properties, Class<T> pojo) { try { T protoMessageInstance = (T) pojo.getMethod("getDefaultInstance").invoke(null); tParser = (Parser<T>) protoMessageInstance.getParserForType(); this.schemaInfo = new SchemaInfo(); this.schemaInfo.setName(""); Map<String, String> allProperties = new HashMap<>(); allProperties.putAll(properties); // set protobuf parsing info allProperties.put(PARSING_INFO_PROPERTY, getParsingInfo(protoMessageInstance)); this.schemaInfo.setProperties(allProperties); this.schemaInfo.setType(SchemaType.PROTOBUF); ProtobufDatumReader datumReader = new ProtobufDatumReader(pojo); org.apache.avro.Schema schema = datumReader.getSchema(); this.schemaInfo.setSchema(schema.toString().getBytes()); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IllegalArgumentException(e); } }
public static <T extends com.google.protobuf.GeneratedMessageV3> ProtobufSchema<T> of( Class<T> pojo, Map<String, String> properties){ return ofGenericClass(pojo, properties); } }
static <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF(Class<T> clazz) { return ProtobufSchema.of(clazz); }
public static ProtobufSchema ofGenericClass(Class pojo, Map<String, String> properties) { if (!com.google.protobuf.GeneratedMessageV3.class.isAssignableFrom(pojo)) { throw new IllegalArgumentException(com.google.protobuf.GeneratedMessageV3.class.getName() + " is not assignable from " + pojo.getName()); } return new ProtobufSchema<>(properties, pojo); }
@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); } }
public static <T extends com.google.protobuf.GeneratedMessageV3> ProtobufSchema<T> of(Class<T> pojo) { return of(pojo, Collections.emptyMap()); }