I need to create a Json payload like this from Java pojo :
{ "update" : {
"labels" : [{"add" : "A label"} ]
}
}
so I created a Java pojo like this :
@JsonRootName(value = "update")
public class AddLabel{
@JsonProperty("labels")
public List<Label> labels;
public AddLabel(String labelName){
this.labels = new ArrayList<>();
this.labels.add(new Label(labelName);
}
public static class Label{
public String add;
public Label(String labelName){
this.add = labelName;
}
}
}
I like to have the "add" property in Label class as dynamic, so that it can also take values such as "remove", "set" . Is there a way to do this other than creating another POJO's for each of them?