0

I have a class that reads a JSON obtained by a callout and it works fine but when I try to do the test class for it I get an error Malformed JSON: Expected '{' at the beginning of object

When I run de class, I see the JSON has this structure but it doesn't generate any error

Also in my code I have

List<Object> result; 
result = (List<Object>) JSON.deserializeUntyped(jsonresponse.getBody());

That's why when the class run it works fine, but I don't understand why I get the error why I run the testclass.

And my mock class

public HTTPResponse respond(HTTPRequest token){
    HttpResponse res = new HttpResponse();
    res.setHeader('Content-Type', 'application/json');
   res.setBody('[{"id":"9157100665465129064",@referredType":"ProductOffering"}],"isRoot":false,"offeringCountMax":999,"offeringCountMin":0,"orderNumber":"1","@type":"Category"}]');
    res.setStatusCode(200);
    return res; 
}
  • 1
    The json in your mock class is not valid. [{data}], otherData}] is what you have. There's an unmatched object and list terminator at the end. – Derek F May 19 at 22:55

Your Answer

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

Browse other questions tagged or ask your own question.