JJSchema:使用Jackson从Java Types到JSON-Schema的生成器

  • y9_984831
    了解作者
  • 88.9KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-27 04:04
    上传日期
JJSchema Java JSON Schema和Hyper-Schema生成器。 当前,它基于v4草案。 支持Java 8日期和时间API。 最新发布 < dependency> < groupId>com.github.reinert</ groupId> < artifactId>jjschema</ artifactId> < version>1.16</ version> </ dependency> 简单的操作方法 假设以下类: @Attributes ( title = " Product " , description = " A product from Acme's catalog " ) static class Product { @Attributes ( required = true , description = " T
JJSchema-master.zip
内容介绍
JJSchema =============== A Java JSON Schema and Hyper-Schema generator. Currently, it is based on v4 draft. Supports Java 8 Date and Time API. Latest Release ---------------- ```xml <dependency> <groupId>com.github.reinert</groupId> <artifactId rel='nofollow' onclick='return false;'>jjschema</artifactId> <version>1.16</version> </dependency> ``` Simple HOW TO ---------------- Suppose the following Class: ```java @Attributes(title="Product", description="A product from Acme's catalog") static class Product { @Attributes(required=true, description="The unique identifier for a product") private long id; @Attributes(required=true, description="Name of the product") private String name; @Attributes(required=true, minimum=0, exclusiveMinimum=true) private BigDecimal price; @Attributes(minItems=1,uniqueItems=true) private List<String> tags; public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } public List<String> getTags() { return tags; } public void setTags(List<String> tags) { this.tags = tags; } } ``` Type the following code: ```java JsonSchemaFactory schemaFactory = new JsonSchemaV4Factory(); schemaFactory.setAutoPutDollarSchema(true); JsonNode productSchema = schemaFactory.createSchema(Product.class); System.out.println(productSchema); ``` The output: ```json { "type" : "object", "description" : "A product from Acme's catalog", "title" : "Product", "properties" : { "id" : { "type" : "integer", "description" : "The unique identifier for a product" }, "name" : { "type" : "string", "description" : "Name of the product" }, "price" : { "type" : "number", "minimum" : 0, "exclusiveMinimum" : true }, "tags" : { "type" : "array", "items" : { "type" : "string" }, "uniqueItems" : true, "minItems" : 1 } }, "required" : [ "id", "name", "price" ], "$schema" : "http://json-schema.org/draft-04/schema#" } ``` Thanks to ---------------- [![IntelliJ](https://lh6.googleusercontent.com/--QIIJfKrjSk/UJJ6X-UohII/AAAAAAAAAVM/cOW7EjnH778/s800/banner_IDEA.png)](http://www.jetbrains.com/idea/index.html)
评论
    相关推荐