【发布时间】:2014-11-29 17:42:39
【问题描述】:
我有一个 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 架构:
{"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"
}
}
【问题讨论】:
-
不,将 pojo 转换为 json 对象。我正在寻找生成 JSON 模式作为元 [有关映射到 pojo 字段的输入表单字段的信息,如数据类型,是否需要等,] 给最终用户)。
-
这里是一个在线站点,它将从 json 生成 json 模式:jsonschema.net
-
其实我不是在寻找任何工具。我需要一个可以有帮助类或注释的 api 来描述 pojo 中字段的行为。例如。我今天最近发现jackson 2.4.1 有新的注释@JsonPropertyDescription 来将描述添加到pojo 中的字段; [链接]stackoverflow.com/questions/24515917/….有没有可能通过反射来实现我帖子中的示例?
标签: json jackson jsonschema fasterxml jackson-modules