Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java代码+;没有任何POJO的GSON_Java_Json_Gson_Jsonschema - Fatal编程技术网

使用java代码+;没有任何POJO的GSON

使用java代码+;没有任何POJO的GSON,java,json,gson,jsonschema,Java,Json,Gson,Jsonschema,我想使用GSON手动创建JSON模式,但在GSON中找不到任何JsonSchema元素支持。我不想将pojo转换为模式,但想通过编程创建模式。在格森有什么办法吗?可能有点像下面 **1 JsonSchema schema = new JsonSchema(); 2 schema.Type = JsonSchemaType.Object; 3 schema.Properties = new Dictionary<string, JsonSchema> 4{ 5 { "n

我想使用GSON手动创建JSON模式,但在GSON中找不到任何JsonSchema元素支持。我不想将pojo转换为模式,但想通过编程创建模式。在格森有什么办法吗?可能有点像下面

 **1 JsonSchema schema = new JsonSchema();
 2 schema.Type = JsonSchemaType.Object;
 3 schema.Properties = new Dictionary<string, JsonSchema>
 4{
 5    { "name", new JsonSchema { Type = JsonSchemaType.String } },
 6    {
 7        "hobbies", new JsonSchema
 8        {
 9            Type = JsonSchemaType.Array,
10            Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String } }
11        }
12    },
13};**
**1 JsonSchema模式=新JsonSchema();
2 schema.Type=JsonSchemaType.Object;
3 schema.Properties=新字典
4{
5{“name”,新的JsonSchema{Type=JsonSchemaType.String},
6    {
7“爱好”,新JsonSchema
8        {
9 Type=JsonSchemaType.Array,
10项=新列表{new JsonSchema{Type=JsonSchemaType.String}
11        }
12    },
13};**
 > p>您可以考虑使用编程方式创建JSON架构。虽然它没有正确的文档记录,但它的构建器类形成了一个fluent API,让您可以使用它。例如:

Schema schema = ObjectSchema.builder()
    .addPropertySchema("name", StringSchema.builder().build())
    .addPropertySchema("hobbies", ArraySchema.builder()
        .allItemSchema(StringSchema.builder().build())
        .build())
    .build();
它的语法与您描述的稍有不同,但可以用于相同的目的


(免责声明:我是的作者)

我试图按照上面的建议构建一个模式,请参见