首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从Java类生成JSON模式

从Java类生成JSON模式
EN

Stack Overflow用户
提问于 2014-10-05 12:50:20
回答 4查看 92.9K关注 0票数 47

我有一个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"
      }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26199716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档