简体   繁体   English

从JSON模式生成Java接口

[英]Generate java interfaces from JSON Schema

I'm looking for tool to work with JSON Schema in java. 我正在寻找在Java中使用JSON Schema的工具。

Main requirement is interface generation. 主要要求是接口生成。 I'd like to get interfaces from parser API and provide my own implementations to serializer API. 我想从解析器API获取接口,并为序列化器API提供自己的实现。 The main purpose is to avoid beans pollution with annotations like JsonProperty , JsonIgnore and so on. 主要目的是避免使用JsonPropertyJsonIgnore等注释来污染豆子。

There are many tools that can generate java beans (classes) from JSON Schema. 有很多工具可以从JSON Schema生成Java bean(类)。 Jackson has a feature @JsonSerialize(as=MyInterface.class) , but I could not find any tools to generate interfaces from schema. 杰克逊具有@JsonSerialize(as=MyInterface.class) ,但是我找不到从架构生成接口的任何工具。

I've never used it, but does http://www.jsonschema2pojo.org/ help? 我从未使用过它,但是http://www.jsonschema2pojo.org/有帮助吗? It seems you can even use it from within Java . 看来您甚至可以在Java中使用它

Let me show you how to dev the tool.you can do so: 让我向您展示如何开发该工具。您可以这样做:

  1. user javascript function Json.parse(),make string like-json trans to js object 用户javascript函数Json.parse(),将字符串like-json转换为js对象
  2. then use this object to genrate the javabean format. 然后使用该对象生成javabean格式。
  3. something,you shoud care.(1)value type mapping,forexample,how to figure out the string,is date type.(2)loweser_case to camelCase 某些事情,您应该注意。(1)值类型映射,例如,如何找出字符串,是日期类型。(2)loweser_case to camelCase

I dev a tool solve the problem.it is well design and quick more. 我开发了一个工具来解决问题。它设计精良,而且速度更快。 get the code from my github . 从我的github获取代码。

enjoy it from here,I have deploy it on webserver . 从这里开始享受它,我已经将它部署在了Web服务器上

I try the top 2 answer's suggestion.one web is can not open.one is slower than my tool.hope you will enjoy my tool. 我尝试了前2个答案的建议。一个网无法打开。一个比我的工具慢。希望您会喜欢我的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM