Grégoire Borel
Grégoire Borel

Reputation: 2028

Serialize nested JSON arrays

I'd like to store data and jsonFormat in variables with @JsonProperty. How do I do that?

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

Upvotes: 0

Views: 1043

Answers (1)

tinker
tinker

Reputation: 1406

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. 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.

Upvotes: 1

Related Questions