I'm sure I'm just being dense here.
I want to take an object schema, and turn it into a string representation.
Like so, but this returns null:
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
JsonSchema jsonSchema = generator.generateSchema(Get.class);
System.out.println("jsonSchema: " + jsonSchema.asObjectSchema().asStringSchema());
This is using com.fasterxml.jackson.module.jsonSchema.JsonSchema, found at https://github.com/FasterXML/jackson-module-jsonSchema/wiki
you can achieve that by doing:
ObjectMapper mapper = new ObjectMapper();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(mapper.constructType(YOURCLASS.class), visitor);
JsonSchema jsonSchema = visitor.finalSchema();
String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
Easily done:
m.writeValueAsString(jsonSchema);
Essentially, using Jackson to marshal the schema object into JSON.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With