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
MaggieSumitMaggieSumit 

Getting Error while saving the class. Please help me on this.

Line no 14 I am getting this error. "Type cannot be constructed: String" Please help me on this.
  1.    public String type_Z {get;set;} 
  2.     public List<String> authcookies {get;set;} 
  3.  
  4.     public JsonStringsss(JSONParser parser) {
  5.         while (parser.nextToken() != JSONToken.END_OBJECT) {
  6.             if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {
  7.                 String text = parser.getText();
  8.                 if (parser.nextToken() != JSONToken.VALUE_NULL) {
  9.                     if (text == 'type') {
  10.                         type_Z = parser.getText();
  11.                     } else if (text == 'auth-cookies') {
  12.                         authcookies = new List<String>();
  13.                         while (parser.nextToken() != JSONToken.END_ARRAY) {
  14.                             authcookies.add(new String(parser));
  15.                         }
  16.                     } else {
  17.                         System.debug(LoggingLevel.WARN, 'Root consuming unrecognized property: '+text);
  18.                         consumeObject(parser);
  19.                     }
  20.                 }
  21.             }
  22.         }
  23.     }
Best Answer chosen by MaggieSumit
Amit Chaudhary 8Amit Chaudhary 8
Please try below code
public String type_Z {get;set;} 
    public List<String> authcookies {get;set;} 
 
    public JsonStringsss(JSONParser parser) {
        while (parser.nextToken() != JSONToken.END_OBJECT) {
            if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {
                String text = parser.getText();
                if (parser.nextToken() != JSONToken.VALUE_NULL) {
                    if (text == 'type') {
                        type_Z = parser.getText();
                    } else if (text == 'auth-cookies') {
                        authcookies = new List<String>();
                        while (parser.nextToken() != JSONToken.END_ARRAY) 
						{
							String str = parser.getText() ;
                            authcookies.add(str);
                        }
                    } else {
                        System.debug(LoggingLevel.WARN, 'Root consuming unrecognized property: '+text);
                        consumeObject(parser);
                    }
                }
            }
        }
    }

Let us know if this will help you
 

All Answers

Shaijan ThomasShaijan Thomas
Hi
 
Not sure what you are trying to add in the authcookies list

if you add in string list the format should be

 authcookies.add(new String(parser.<Method>));
for example  authcookies.add(new String(parser.GetText));

Thanks
Amit Chaudhary 8Amit Chaudhary 8
Please try below code
public String type_Z {get;set;} 
    public List<String> authcookies {get;set;} 
 
    public JsonStringsss(JSONParser parser) {
        while (parser.nextToken() != JSONToken.END_OBJECT) {
            if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {
                String text = parser.getText();
                if (parser.nextToken() != JSONToken.VALUE_NULL) {
                    if (text == 'type') {
                        type_Z = parser.getText();
                    } else if (text == 'auth-cookies') {
                        authcookies = new List<String>();
                        while (parser.nextToken() != JSONToken.END_ARRAY) 
						{
							String str = parser.getText() ;
                            authcookies.add(str);
                        }
                    } else {
                        System.debug(LoggingLevel.WARN, 'Root consuming unrecognized property: '+text);
                        consumeObject(parser);
                    }
                }
            }
        }
    }

Let us know if this will help you
 
This was selected as the best answer
MaggieSumitMaggieSumit
thanks but its not working, actually I have converted JSON in apex class using converter now I am trying to save the class but getting this error.

this is JSON response. JSESSIONID id i am trying to store

{
  "type": "loginAnswer",
  "state": 0,
  "data": {
    "type": "tenantOwner",
    "blocked": false,
    "created-at": "2017-01-05T18:42:14Z",
    "credentials-id": "ad18e3fdf6af48a391b20ccd07776a6f",
  },
  "auth-cookies": [
    "JSESSIONID=66977ff4536c177e0e8c2f2c65fb; Path=/coe; HttpOnly"
  ]

}
MaggieSumitMaggieSumit
Thanks @Amit Chaudhary 8