The reason for this is in my Selenium tests, I am mocking the REST services to return POJOs with hardcoded values, which represents my dummy data. One of the pages requires a list of objects who has heaps of fields and children Java objects (think Person has List, List, etc.).
A quick way I did was generate a JSON string from one of the REST services that pulls from the database. So now, I have a JSON string which I saved as a file and can load into my Selenium test as my hardcoded data. However, I want to maintain this in the Java code rather than a separate file, the data.json file.
Is there a way to generate Java code, which is basically lines and lines of setters where the values come from the JSON? I am trying to avoid having to hand-code each setter for each fields....
Example json file (in reality it has more fields and more children...):
{
"personEntity":{
"name":"xxx",
"dob":"2000-01-01",
"address":[
{
"id":"1",
"line1":"123"
},
{
"id":"2",
"line1":"zzz"
}
],
"phones":[
{
"id":"1",
"number":"999-999-999"
}
]
}
}
Desired Java code that is auto-generated:
Person p = new Person();
p.setName("xxx");
p.setDob("2000-01-01");
Address a1 = new Address();
a1.setId(1);
a1.setLine1("123")
p.addAddress(a1);
// and so on for the other fields
NOTE:
The POJOs are already existing and are NOT needed to be auto-generated. The only auto-generated code I am looking for is the sample above such as p.setName("xxx") and so on for the other fields.