我相信我只是在这里密集.
我想采用对象模式,并将其转换为字符串表示形式.
像这样,但这返回null:
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
JsonSchema jsonSchema = generator.generateSchema(Get.class);
System.out.println("jsonSchema: " + jsonSchema.asObjectSchema().asStringSchema());
这是使用com.fasterxml.jackson.module.jsonSchema.JsonSchema,发现于https://github.com/FasterXML/jackson-module-jsonSchema/wiki
解决方法:
你可以做到这一点:
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);