I have json like
{
"key" : ["key1", "key2", "key3"],
"value" : "v1";
}
I de-serialize it to my class Pojousing jackson, although for de-serialization I want the variable to valuebe a type List<String>whose size will depend on the size of the variable key. So the final object will represent this Json.
{
"key" : ["key1", "key2", "key3"],
"value" : ["v1", "v1", "v1"];
}
So far, the class is Pojoas follows
public class Pojo {
@JsonProperty("key")
private List<String> key;
@JsonProperty("value")
private List<String> value;
@JsonProperty("key")
public List<String> getKey() {
return key;
}
@JsonProperty("key")
public void setKey(List<String> key) {
this.key = key;
}
@JsonProperty("value")
public List<String> getValue() {
return value;
}
@JsonProperty("value")
public void setValue(String val) {
List<String> arr = new ArrayList<String>();
for (int i=0; i<key.size(); i++) {
arr.add(val);
}
this.value = arr;
}
}
but i get JsonMappingException. During debugging, I found that keythere is a setValue method inside the variable null. Is there a way to set the value of the variable first key(before the variable value)
source
share