function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ritesh__Ritesh__ 

System.JSONException: Unexpected character ('o' (code 111)):

i am writing a test class for my apex custom controller

@isTest
public class TestGoogleLoginController {
public static testMethod void testGoogleLogin(){
PageReference pageRef = Page.GoogleLogin;
        Test.setCurrentPage(pageRef);
GoogleLoginController testCon = new GoogleLoginController();
 testCon.googleApp.Name        = 'Test Google';
       testCon.googleApp.ClientId__c     = 'TestClientID';
       testCon.googleApp.ClientSecret__c = 'TestClientSecret';
       testCon.googleApp.Scope__c        = 'Full';

       testCon.saveGoogleSettings();

        system.assertEquals(false,testCon.isEditMode);

      testCon.getfieldsToDisplay();

      testCon.setfieldsToDisplay(new List<String>());
       testCon.getOptionalFields();
       testCon.getTimes();
       testCon.getFrequencies();
       testCon.editSettings();
       testCon.resetSettings();
       HttpResponse res = new HttpResponse();
       res.setStatusCode(200);
       res.setBody('{"access_token":"testtoken","expires_in":3600,"refresh_token":"testrefresh"}');

     //  testCon.testnewToken = GoogleTestHelper.returnGCalendarResp();


       testCon.testStringResponse='{'
 +'"kind": "calendar#calendarList",'
 +'"etag": "\"ornOQ71wXvJyYxXJastrexEVbhI/cahY1tW4ufW7_T7RZX6lctFgxTs\"",'
 +'"items": ['
  +
  '{'

   +'"kind": "calendar#calendarListEntry",'
   +'"etag": "\"ornOQ71wXvJyYxXJastrexEVbhI/O2iwFWmuTeTtE-FHvIebAXyATNA\"",'
   +'"id": "#contacts@group.v.calendar.google.com",'
   +'"summary": "Contacts\' birthdays and events",'
   +'"description": "Your contacts\' birthdays and anniversaries",'
   +'"timeZone": "Asia/Calcutta",'
   +'"colorId": "12",'
   +'"backgroundColor": "#fad165",'
   +'"foregroundColor": "#000000",'
   +'"selected": true,'
   +'"accessRole": "reader"'
  +'},'
  +'{'

   +'"kind": "calendar#calendarListEntry",'
   +'"etag": "\"ornOQ71wXvJyYxXJastrexEVbhI/EuXdDiUebGTzeu_H2b77ywuPg5I\"",'
   +'"id": "en.indian#holiday@group.v.calendar.google.com",'
   +'"summary": "Indian Holidays",'
   +'"description": "Indian Holidays",'
   +'"timeZone": "Asia/Calcutta",'
   +'"colorId": "9",'
   +'"backgroundColor": "#7bd148",'
   +'"foregroundColor": "#000000",'
   +'"accessRole": "reader"'
  +'},'
  +'{'

   +'"kind": "calendar#calendarListEntry",'
   +'"etag": "\"ornOQ71wXvJyYxXJastrexEVbhI/Mwoop52s5b3-Jh82u4_w_xVY4Nc\"",'
   +'"id": "riteshmehandiratta@gmail.com",'
   +'"summary": "riteshmehandiratta@gmail.com",'
   +'"timeZone": "Asia/Calcutta",'
   +'"colorId": "15",'
   +'"backgroundColor": "#9fc6e7",'
   +'"foregroundColor": "#000000",'
   +'"selected": true,'
   +'"accessRole": "owner",'
   +'"defaultReminders": ['
    +'{'
     +'"method": "email",'
     +'"minutes": 10'
    +'},'
    +'{'
     +'"method": "popup",'
     +'"minutes": 10'
    +'}'
   +'],'
   +'"primary": true'
  +'}'
 +']'
+'}';
       testCon.getCalendars();


}

}

when i run this test i am getting error

System.JSONException: Unexpected character ('o' (code 111)): was expecting comma to separate OBJECT entries at [line:1, column:45]

    (System Code)
    Class.JSON2Apex.parse: line 14, column 1
    Class.GoogleLoginController.getCalendars: line 557, column 1
    Class.TestGoogleLoginController.testGoogleLogin: line 110, column 1

i am clueless why i am facing this error

my JSON2Apex class is public class JSON2Apex {

public String kind; 
public String etag; 
public List<Items> items; //this list represent google Calendar list  in the Authenticated Calendar 

//parse Method for converting a JSON response into JSON2Apex
public static JSON2Apex parse(String json) {
    return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
}}

and code for Items class is

public class Items {
        public String kind; //kind of the Google Calendar
        public String etag; //etag of the Google Calendar
        public String id;  //id of the Google Calendar
        public String summary; //summary of the Google Calendar
        public String description; //Description of google Calendar
        public String timeZone; //timeZone of the Google Calendar
        public String colorId; //ColorId of the Calendar
        public String backgroundColor; //Background Color of the Calendar
        public String foregroundColor; //ForeGround Color Of the Calendar
        public Boolean selected;  
        public String accessRole;
        public List<DefaultReminders> defaultReminders; //Default Remainder Configuration of the Calendar

        public class DefaultReminders {
        public String method; //Method For Reminding for an event
        public Integer minutes; 
    }

    }

and code for getCalendar method is

public void getCalendars(){
 536        GCalendarUtil.GResponse response;
 537        
 538          if(googleapp.ExpiresIn__c < system.now()){
 539       if(!Test.isRunningTest())
 540                  response = GCalendarUtil.getNewToken(googleapp);
 541              else
 542                  response = testnewToken;
 543             
 544              accessToken  = response.access_token;
 545           
 546            }else{
 547      
 548              accessToken = googleapp.AccessToken__c;
 549      
 550            }
 551            String resp;
 552            if(!Test.isRunningTest())
 553                  resp = GCalendarUtil.doAPICall(null, 'GET','https://www.googleapis.com/calendar/v3/users/me/calendarList',accessToken);
 554              else
 555                  resp = testStringResponse;       
 556            
 557          JSON2Apex apexObject=JSON2Apex.parse(resp);
 558      
 559       ls = new Map<String,String>();
 560      
 561      List<Items> itemlist= apexObject.items ; 
 562      
 563      for(Items item:itemlist)
 564      ls.put(item.id,item.summary);
 565        
 566        for(CalendarSettings__c c: newCalSettings){
 567        c.Google_Calendar_Name__c = ls.get(c.name);  
 568             }
 569        }

why i am facing this error please some one help ??

SanGeorgeSanGeorge

This is a common issue when you try creating apex code from sites like json2apex. The value being parsed is bigger that the datatype. Try changing an Integer to long.