I have a very simple class and Web Service. The resulting JSON shows that the payload is getting serialized twice. Could you please point out my error?
public class JSONFactory {
public Integer id;
public String name;
public String lastName;
public JSONFactory(Integer a, String b, String c){
this.id = a;
this.name = b;
this.lastName = c;
}
}
@RestResource(urlMapping='/Johnny')
global class WebServiceFactory {
@HttpGet
global static String getRecord() {
List<JSONFactory> JSONs = new List<JSONFactory>();
for(integer i = 0; i<4; i++){
JSONs.add(new JSONFactory(i, 'Jan' + i, 'Test' + i));
}
return JSON.serialize(JSONs);
}
}
Resulting JSON (serialized twice):
[{\"name\":\"Jan0\",\"lastName\":\"Test0\",\"id\":0},
{\"name\":\"Jan1\",\"lastName\":\"Test1\",\"id\":1},
{\"name\":\"Jan2\",\"lastName\":\"Test2\",\"id\":2},
{\"name\":\"Jan3\",\"lastName\":\"Test3\",\"id\":3}]