**I am Accessing the Class using postMan I am Writing the Code like
@RestResource(urlMapping='/create Event2/')
global class JSON2Apex {
@Httppost
global static void consumeObject(JSONParser parser) {
It is Showing Error like
Error: Compile Error: Invalid type for Http* method: System.JSONParser at line 6 column 24
How to Rectify the Error**
This is My Entire Code:
@RestResource(urlMapping='/create Event2/')
global class JSON2Apex {
@Httppost
global static void consumeObject(JSONParser parser) {
system.debug(parser);
Integer depth = 0;
do {
JSONToken curr = parser.getCurrentToken();
system.debug(curr);
if (curr == JSONToken.START_OBJECT ||
curr == JSONToken.START_ARRAY) {
depth++;
} else if (curr == JSONToken.END_OBJECT ||
curr == JSONToken.END_ARRAY) {
depth--;
}
} while (depth > 0 && parser.nextToken() != null);
}
public List<Eventitems> eventitems {get;set;}
public JSON2Apex(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 == 'eventitems') {
eventitems = new List<Eventitems>();
while (parser.nextToken() != JSONToken.END_ARRAY) {
eventitems.add(new Eventitems(parser));
}
} else {
System.debug(LoggingLevel.WARN, 'Root consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
public class Eventitems {
public String whatid {get;set;}
public String whoid {get;set;}
public String OwnerId {get;set;}
public Boolean IsAllDayEvent {get;set;}
public String Subject {get;set;}
public String StartDate {get;set;}
public String EndDate {get;set;}
public Boolean Recurrence {get;set;}
public String Recurrencestdate {get;set;}
public String Recurrenceenddate {get;set;}
public String RecType {get;set;}
public String Recintrvl {get;set;}
public List<String> Invitees {get;set;}
public Eventitems(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 == 'whatid') {
whatid = parser.getText();
} else if (text == 'whoid') {
whoid = parser.getText();
} else if (text == 'OwnerId') {
OwnerId = parser.getText();
} else if (text == 'IsAllDayEvent') {
IsAllDayEvent = parser.getBooleanValue();
} else if (text == 'Subject') {
Subject = parser.getText();
} else if (text == 'StartDate') {
StartDate = parser.getText();
} else if (text == 'EndDate') {
EndDate = parser.getText();
} else if (text == 'Recurrence') {
Recurrence = parser.getBooleanValue();
} else if (text == 'Recurrencestdate') {
Recurrencestdate = parser.getText();
} else if (text == 'Recurrenceenddate') {
Recurrenceenddate = parser.getText();
} else if (text == 'RecType') {
RecType = parser.getText();
} else if (text == 'Recintrvl') {
Recintrvl = parser.getText();
} else if (text == 'Invitees') {
Invitees = new List<String>();
while (parser.nextToken() != JSONToken.END_ARRAY) {
//Invitees.add(new String(parser));
}
} else {
System.debug(LoggingLevel.WARN, 'Eventitems consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
}
public static JSON2Apex parse(String json) {
return new JSON2Apex(System.JSON.createParser(json));
}
}
consumeObject
method use that class (Json2Apex generated class) for deserialize. check this ceus-now.com/how-to-deserialize-a-json-string-to-apex