简体   繁体   English

如何使用 json 模式生成内部 Java 类?

[英]How to generate inner java classes with json schema?

Is it possible to generate inner java classes using json schema?是否可以使用 json 模式生成内部 Java 类? The plugin I am using for generating my pojos is jsonschema2pojo( http://www.jsonschema2pojo.org/ )我用来生成我的 pojo 的插件是 jsonschema2pojo( http://www.jsonschema2pojo.org/ )

If yes, how?如果是,如何?

Currently I couldn't find any information/examples regarding this on web, neither on http://json-schema.org/ or on http://www.jsonschema2pojo.org/目前我在网络上找不到任何关于此的信息/示例,无论是在http://json-schema.org/还是在http://www.jsonschema2pojo.org/

No. I have experimented with this trying to achieve the same and have concluded that jsonschema2Pojo doesn't support it.不。我已经尝试过尝试实现相同的目标,并得出结论 jsonschema2Pojo 不支持它。

Neither两者都不

{
...
   "foo": {
      "$ref" : "#/definitions/Bar.Foo"
   }
...
"definitions" : {
   "Bar.Foo": {
      "type": object,
      ...
   }
}

or或者

{
...
   "foo": {
      "$ref" : "#/definitions/Foo"
   }
...
"definitions" : {
   "Foo": {
      "type": object,
      "javaType": "org.example.Bar.Foo"
      ...
   }
}

works.作品。

I'd recommend posting this issue to their jira, last time I checked they were quite responsive.我建议将此问题发布到他们的 jira,上次我检查他们的反应非常灵敏。

You might also want to consider other limitations of jsonschema2Pojo and think about whether the tool makes sense at all.您可能还想考虑 jsonschema2Pojo 的其他限制,并考虑该工具是否有意义。

On the project I have been working on it is becoming more more clear that we might have been better off not using the tool at all, because people have been inventing all kinds of exotic workarounds to compensate for shortcomings of the tool (like being able to specify a base class for a generated class.在我一直从事的项目中,越来越清楚的是,我们根本不使用该工具可能会更好,因为人们一直在发明各种奇特的变通方法来弥补该工具的缺点(例如能够为生成的类指定基类。

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

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