eolivelli commented on a change in pull request #9614:
URL: https://github.com/apache/pulsar/pull/9614#discussion_r589278487



##########
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:
       A couple of reasons:
   - I am adding this specification because this way the user won't have to 
deal with ClassCastExceptions or to use 'instanceof'.
   - Also the implementation of GenericRecord will be allowed to implement some 
"compatibility" feature.
   For instance if in the future we will move away from JsonNode but the client 
code still expects to receive a JsonNode, we will be able to return a properly 
crafted JsonNode instance and to not break clients.
   I am not saying we will do this soon, but if we do not add such support we 
won't be able to add it in the future.
   




----------------------------------------------------------------
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


Reply via email to