Sar*_*thi 6 json code-generation jsonschema
我想从给定的 JSON Schema草案 4 版本生成 JAVA 类
我评估了几个工具,发现jsonschema2pojo很有用。但它仅支持 json 模式草案 3 版本(尽管 json 模式草案 4 在其路线图中)。
谁能建议我一个从 json 模式生成 java 类的工具或方法(符合 json 模式草案4)?提前致谢。
您可以尝试cog,这是一个用 Ruby 编写的通用代码生成器。我在 github 上放置了一个名为json2java的简单项目,它演示了如何使用 cog 从 json 数据生成 Java 类。
不确定你到底想做什么,但这是我的假设。json 数据看起来像这样
{
"classname": "Sample",
"methods": [
{
"name": "foo",
"rtype": "void",
"params": [
{
"name": "arg1",
"type": "int"
}
]
},
{
"name": "bar",
"rtype": "int",
"params": []
}
]
}
Run Code Online (Sandbox Code Playgroud)
相应的 Java 类看起来像这样
public class Sample {
void foo(int arg1) {
// keep: foo {
// While the interface in this example is generated,
// the method bodies are preserved between multiple invocations
// of the generator.
// It doesn't have to be done this way, the method bodies can be
// generated aswell, all depends on what your json data encodes
// keep: }
}
int bar() {
// keep: bar {
return 1;
// keep: }
}
}
Run Code Online (Sandbox Code Playgroud)
如果您想尝试 cog,请像这样安装它gem install cog,并像这样运行生成器cog gen。查看 cog 主页以获取文档。
| 归档时间: |
|
| 查看次数: |
6046 次 |
| 最近记录: |