我有一个 POJO 类:
public class Stock {
int id;
String name;
Date date;
}
是否有任何注释或开发框架/API 可以将 POJO 转换为 JSON 模式,如下所示:
{"id":
{
"type" : "int"
},
"name":{
"type" : "string"
}
"date":{
"type" : "Date"
}
}
我还可以"Required" : "Yes"
通过在 POJO 上指定一些注释或配置来扩展模式以添加信息,例如每个字段的描述等,并且可以生成如下所示的 JSON 模式:
{"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"
}
}