sijie commented on a change in pull request #2578: [WIP] Add support for schema extraction from a jar URL: https://github.com/apache/incubator-pulsar/pull/2578#discussion_r217571498
########## File path: pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/utils/SchemaExtractor.java ########## @@ -0,0 +1,29 @@ +package org.apache.pulsar.admin.cli.utils; + +import org.apache.avro.Schema; +import org.apache.avro.reflect.ReflectData; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.schema.JsonSchema; + +import java.io.IOException; + +public class SchemaExtractor { + + public static String getJsonSchema(Class clazz) throws IOException { + + org.codehaus.jackson.map.ObjectMapper mapper = new ObjectMapper(); + mapper.configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, true); + + JsonSchema schema = mapper.generateJsonSchema(clazz); + + return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema); + } + + public static String getAvroSchema(Class clazz) { Review comment: use `Schema.AVRO(class).getSchemaInfo()` to get schema ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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