merlimat commented on a change in pull request #3752: revise the schema default type not null URL: https://github.com/apache/pulsar/pull/3752#discussion_r264962895
########## File path: pulsar-client-api/src/main/java/org/apache/pulsar/client/api/Schema.java ########## @@ -167,25 +168,47 @@ default T decode(byte[] bytes, byte[] schemaVersion) { } /** - * Create a Avro schema type by extracting the fields of the specified class. + * Create a Avro schema type by default configuration of the class * * @param clazz the POJO class to be used to extract the Avro schema * @return a Schema instance */ static <T> Schema<T> AVRO(Class<T> clazz) { - return DefaultImplementation.newAvroSchema(clazz); + return DefaultImplementation.newAvroSchema(new SchemaDefinition<>(clazz)); } /** - * Create a JSON schema type by extracting the fields of the specified class. + * Create a Avro schema type with schema definition + * + * @param schemaDefinition the definition of the schema + * @return a Schema instance + */ + static <T> Schema<T> AVRO(SchemaDefinition<T> schemaDefinition) { + return DefaultImplementation.newAvroSchema(schemaDefinition); + } + + + /** + * Create a JSON schema type by default configuration of the class * * @param clazz the POJO class to be used to extract the JSON schema * @return a Schema instance */ static <T> Schema<T> JSON(Class<T> clazz) { - return DefaultImplementation.newJSONSchema(clazz); + return DefaultImplementation.newJSONSchema(new SchemaDefinition<>(clazz)); + } + + /** + * Create a JSON schema type with schema definition + * + * @param schemaDefinition the definition of the schema + * @return a Schema instance + */ + static <T> Schema<T> JSON(SchemaDefinition schemaDefinition) { Review comment: I think that JSON is a bit different compared with AVRO in that it does not have a canonical schema representation. In AVRO, the schema def is the source of truth, but for JSON the pojo is typically the source of truth (and people use annotations to customize the specific fields). For now I'd prefer to not add it. We can always add it later if there are good reasons for it (but we'd not be able to take it out once it's in there). ---------------------------------------------------------------- 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 With regards, Apache Git Services