【发布时间】:2020-06-14 03:57:12
【问题描述】:
我们使用 jsonschema2pojo-maven-plugin 从 json 模式文件生成 java pojos。该插件正在为从架构中引用的定义生成 pojo,但不是为所有定义。
是否有任何选项可以让插件为 schmea 中的所有定义生成 pojo?
下面是使用的pom插件配置和schema定义,这里是插件
- 仅为产品定义生成 POJO
- 不为产品子类定义(“proprietaryProduct”和“thirdPartyProduct”)生成 POJO
这就是问题所在,我们还需要为这些子类定义生成 pojos
Maven 插件配置:
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-models</id>
<configuration>
<targetPackage>com.xyz.abc</targetPackage>
<useCommonsLang3>true</useCommonsLang3>
</configuration>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Json 架构:
{
"$schema":"http://json-schema.org/draft-04/schema",
"definitions":{
"product":{
"type":"object",
"properties":{
"type":{
"enum":[
"THIRD_PARTY",
"PROPRIETARY"
],
"type":"string"
},
"price":{
"type":"string"
}
},
"additionalProperties": false
},
"proprietaryProduct": {
"type": "object",
"properties": {
"batchName": {
"type": "string"
}
},
"extends": "#/definitions/product"
},
"thirdPartyProduct": {
"type": "object",
"properties": {
"thirdPartyName": {
"type": "string"
}
},
"extends": "#/definitions/product"
}
},
"type":"object",
"properties":{
"product":{
"type":"object",
"$ref":"#/definitions/product"
}
},
"additionalProperties":false
}
【问题讨论】:
-
您会收到哪些日志消息。你有没有用 -X 详细模式运行 maven 来查看插件在做什么?
-
Maven 日志没有提供太多线索——它只检测产品类定义,而不是子类定义。但是,当我使用任何子类定义(如“$ref”:“#/definitions/proprietaryProduct”)在架构中添加引用时 - 正在创建相应的子类 POJO。
标签: java json maven jsonschema jsonschema2pojo