sijie commented on a change in pull request #9614: URL: https://github.com/apache/pulsar/pull/9614#discussion_r589775204
########## File path: pulsar-client-api/src/main/java/org/apache/pulsar/client/api/schema/GenericRecord.java ########## @@ -61,4 +64,29 @@ default Object getField(Field field) { */ Object getField(String fieldName); + /** + * Return the schema tyoe. + * + * @return the schema type + * @throws UnsupportedOperationException if this feature is not implemented + * @see SchemaType#AVRO + * @see SchemaType#PROTOBUF_NATIVE + * @see SchemaType#JSON + */ + default SchemaType getSchemaType() { + throw new UnsupportedOperationException(); + } + + /** + * Return the internal native representation of the Record, + * like a AVRO GenericRecord. + * You have to pass the type you would like to obtain. + * This method will return null if such type is not supported. + * + * @return the internal representation of the record, or null if the requested information is not available. + */ + default <T> T getNativeRecord(Class<T> clazz) { + return null; Review comment: Why not throw UnsupportedOperationException for `getNativeRecord`? It is a much clear behavior than returning `null`. ########## File path: pulsar-client-api/src/main/java/org/apache/pulsar/client/api/schema/GenericRecord.java ########## @@ -61,4 +64,29 @@ default Object getField(Field field) { */ Object getField(String fieldName); + /** + * Return the schema tyoe. + * + * @return the schema type + * @throws UnsupportedOperationException if this feature is not implemented + * @see SchemaType#AVRO + * @see SchemaType#PROTOBUF_NATIVE + * @see SchemaType#JSON + */ + default SchemaType getSchemaType() { + throw new UnsupportedOperationException(); + } + + /** + * Return the internal native representation of the Record, + * like a AVRO GenericRecord. + * You have to pass the type you would like to obtain. + * This method will return null if such type is not supported. + * + * @return the internal representation of the record, or null if the requested information is not available. + */ + default <T> T getNativeRecord(Class<T> clazz) { Review comment: I am not sure about that. Having `Class<T> clazz` means that the users need to know what exactly class that each schema type will use. This will be exactly the same as what I comment on https://github.com/apache/pulsar/pull/9614#issuecomment-784921400. There is no difference between these two approaches. Because people anyway need to know what exactly class to use, I will instead suggest keeping the interface as simple as `Object getNativeRecord()`. Returning `Object` is very commonly seen in a lot of data processing engines that are dealing with different object types. I don't see it is a big problem to do the same thing here. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org