I am serializing the Json from POJO class. I want to send empty array in Request but when i pass null or empty value to the properties in pojo class, i am getting [""] in array list instead of []
Expected: "Key": []
But I am getting: "Key":[""]
My pojo:
public class Sample {
private List<String> Key=null;
}
Test data builder class:
Sample s = new Sample();
s.Key = ""; // Even if i give null here, i am getting null at the json payload.
Pls suggest ways to construct an empty array for Key as below.
{
"Key": []
}
CodePudding user response:
Just initialize new ArrayList, like this.
Sample s = new Sample();
s.Key = new ArrayList<>();