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

标签 java json enums jsonschema jsonschema2pojo

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/

相关文章:

java - 关闭自动提交如何帮助在 JDBC 中启动事务?

javascript - 如何让 jQuery .get 返回 JSON 数据?

c++ - 通过宏定义一个 Enum/Struct 需要什么?

php - 在 Laravels Eloquent 中获取枚举选项

java - 改进嵌套枚举定义

java - JPA @TableGenerator 在多个实体之间共享

java - 如何在 JFreeChart 中以秒为单位省略分数?

java - 用Gson解析Json,没有[]的数组?

javascript - 使用 JavaScript 交换 API

c# - 使用 C# 进行 JSON 反序列化的问题