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); } }