简体   繁体   English

序列化嵌套的JSON数组

[英]Serialize nested JSON arrays

I'd like to store data and jsonFormat in variables with @JsonProperty . 我想使用@JsonPropertydatajsonFormat存储在变量中。 How do I do that? 我怎么做?

{
   "data": [{
             "jsonFormat": {
                 "format": "sliced",
                 "rules": [{ "key": ["NM_OBS"], "sliceName": "FCT_CONS"}]
        }
    }]
}

You can create classes which have the following structure 您可以创建具有以下结构的类

class AnyName {
    private List<JsonFormat> data;
}

class JsonFormat {
    private String format;
    private List<Map<String, Object>> rules;
}

Add the getters and setters and then just use Jackson or GSON to serialize/deserialize the data. 添加获取器和设置器,然后仅使用Jackson或GSON来序列化/反序列化数据。 If you want the rules to be something more specific than Map<String, Object> then you can create a custom deserializer and have a Rules interface which is sub-typed. 如果您希望规则比Map<String, Object>更具体Map<String, Object>则可以创建一个自定义反序列化器,并具有一个子类型的Rules接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM