gpt4 book ai didi

java - JSON 模式到 POJO - 枚举作为一个单独的 java 文件

转载 作者:行者123 更新时间:2023-11-29 07:35:58 26 4
gpt4 key购买 nike

Type.json(枚举)

{
"type" : "string",
"$schema" : "http://json-schema.org/draft-04/schema#",
"title": "type resource",
"name": "type resource",
"description": "List of types",
"id" : "type:v1",
"enum" :
[
"ACC1",
"ACC2"
]
}

Pojo1.json

"properties":{
"type" : {
"$ref" : "Type.json"
},
}

Pojo2.json

"properties":{
"type" : {
"$ref" : "Type.json"
},
}

它不是为枚举创建一个单独的 java 文件,而是在其中一个 POJO 中创建一个枚举,并且这个内部公共(public)枚举由另一个 POJO 引用。

Pojo2.java

private com.Pojo1.Type type;

如何为枚举创建一个单独的 java 文件?谢谢

最佳答案

它看起来不像是创建枚举,因为在 jsonschema2pojo 中支持单独的类作为一个选项。

枚举的生成由 org.jsonschema2pojo.rules.EnumRule 执行

其中的 javadoc 声明:

A Java {@link Enum} is created, with constants for each of the enum values present in the schema. The enum name is derived from the nodeName, and the enum type itself is created as an inner class of the owning type. In the rare case that no owning type exists (the enum is the root of the schema), then the enum becomes a public class in its own right.

听起来你需要提出一个功能请求

关于java - JSON 模式到 POJO - 枚举作为一个单独的 java 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35772338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com