我有一个POJO类:
public class Stock {
int id;
String name;
Date date;
}
是否有任何注释或开发框架/API可以将POJO转换为JSON模式,如下所示:
{"id":
{
"type" : "int"
},
"name":{
"type" : "string"
}
"date":{
"type" : "Date"
}
}
我还可以通过在POJO上指定一些注释或配置来扩展模式,以添加"Required" : "Yes"
、每个字段的描述等信息,并可以生成如下所示的JSON schema:
{"id":
{
"type" : "int",
"Required" : "Yes",
"format" : "id must not be greater than 99999",
"description" : "id of the stock"
},
"name":{
"type" : "string",
"Required" : "Yes",
"format" : "name must not be empty and must be 15-30 characters length",
"description" : "name of the stock"
}
"date":{
"type" : "Date",
"Required" : "Yes",
"format" : "must be in EST format",
"description" : "filing date of the stock"
}
}
发布于 2014-10-24 05:00:44
Jackson JSON Schema模块就是这样一个工具:
https://github.com/FasterXML/jackson-module-jsonSchema
它使用Jackson数据库的POJO内省来遍历POJO属性,并考虑到Jackson注释,并生成一个JSON Schema对象,然后可以将该对象序列化为JSON或用于其他目的。
发布于 2021-03-16 06:24:55
Java JSON Schema Generator:https://github.com/victools/jsonschema-generator
使用Jackson从Java类创建JSON Schema (草案6、草案7或草案2019-09)。
发布于 2015-11-06 02:55:13
使用JJschema。它可以生成符合草案4的JSON模式。有关详细信息,请参阅此帖子http://wilddiary.com/generate-json-schema-from-java-class/。
虽然Jackson Json Schema module也可以生成模式,但到目前为止,它只能生成符合草案3的模式。
https://stackoverflow.com/questions/26199716
复制相似问题