I an trying to write a testclass for a JSON object but het the error:

Illegal assignment from List to or_guestsJSON. How do I annotate the list in my testclass?


    public class or_guestsJSON {
    public String lastLogin;
    public String lastName;
    public String zipCode;
    public String linkedinURL;
    public String city;
    public static List<or_guestsJSON> parse(String json) {
        return (List<or_guestsJSON>) System.JSON.deserialize(json, List<or_guestsJSON>.class);


public class or_guestsJSONTest  {

 static testMethod void guestsTest() {
        String json=        '[{'+
        '    "lastLogin": "2018-05-20 10:33:41.0",'+
        '    "lastName": "GuestLast",'+
        '    "zipCode": "00000",'+
        '    "linkedinURL": "www.linkedin.com/guestprofile",'+
        '    "city": "California",'+
        or_guestsJSON obj = or_guestsJSON.parse(json);
        System.assert(obj != null);

1 Answer 1


or_guestsJSON obj = or_guestsJSON.parse(json); is your problem. The return value is a list, so you must create a list to hold the results:

or_guestsJSON[] obj = or_guestsJSON.parse(json);

... or ...

List<or_guestsJSON> obj = or_guestsJSON.parse(json);

Whichever you feel more comfortable using.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.