将 json 模式中的 ref 用于 pojo 时出错

Error in using ref in json schema to pojo

我正在尝试使用 jsonschema2pojo 生成 Java classes。我 运行 在使用“$ref”标签引用父模式中的其他模式时遇到了麻烦。


Device.json

{
    "$schema": "http://json-schema.org/draft-03/hyper-schema",
    "additionalProperties": false,
    "id": "device:v1",
    "name": "device",
    "properties": {
        "components": {
            "$ref": "spec.json"
            },
        "usage": {
            "$ref": "spec.json"
            }
    }
},
"required": true,
"title": "Device",
"type": "object"
}

这是我的 spec.json

{
    "$schema": "http://json-schema.org/draft-03/hyper-schema",
    "additionalProperties": false,
    "id": "spec:v1",
    "name": "spec",
    "properties": {
        "content": {
            "description" : "Content",
            "type": "string",
            "required": false
    }
},
"required": true,
"title": "spec",
"type": "object"
}

现在我希望创建以下 java class:

public class Device {
    private Spec components,
    private Spec usage

    .....
}

public class Spec {
    private String content
}

但我明白了

public class Device {
    private Components components,
    private Components usage

    .....
}

public class Components {
    private String content
}

我做错了什么?

感谢 here 的回答,作者是 joelittlejohn。我使用 spec.json

中的 javaType 让这个工作

Device.json

{
    "$schema": "http://json-schema.org/draft-03/hyper-schema",
    "additionalProperties": false,
    "id": "device:v1",
    "name": "device",
    "properties": {
        "components": {
            "$ref": "spec.json",
            "type": "object",
            },
        "usage": {
            "$ref": "spec.json",
            "type": "object",
            }
    }
},
"required": true,
"title": "Device",
"type": "object"
}

Spec.json

{
    "$schema": "http://json-schema.org/draft-03/hyper-schema",
    "additionalProperties": false,
    "javaType": "my-package-name.Spec"
    "id": "spec:v1",
    "name": "spec",
    "properties": {
        "content": {
            "description" : "Content",
            "type": "string",
            "required": false
    }
},
"required": true,
"title": "spec",
"type": "object"
}