I have a webservice, and I'm trying to send a List of Apex classes to my SFDC org. Before I even get anywhere in my POST method Salesforce just returns an error.
Sample JSON:
{"FieldParser": {
{"fieldName": "producerCode", "value": ""}, {"fieldname": "description", "value": "otherval"}}
Code:
@RestResource(urlMapping='/StagingREST/*')
global with sharing class EVantageAccountRest
{
global List<FieldParser> FieldParser;
global class FieldParser {
public String fieldName;
public String value;
}
public static JSON2Apex parse(String json) {
return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
}
@HttpPost
global static JSONStatus saveAccount(String jsonString)
{
//it doesn't even reach the code in here.
System.debug('string = ' + jsonString);
return new JSONStatus(false, 'string = ' + jsonString, null);
}
}
JSON2Apex:
public class JSON2Apex {
public List<FieldParser> FieldParser;
public class FieldParser {
public String fieldName;
public String value;
}
public static JSON2Apex parse(String json) {
return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
}
}
Any ideas? For some reason SFDC seems to think this JSON string being passed is bad.
{}
in your JSON, shouldn't it be{"FieldParser": { "fieldName": "producerCode", "value": ""}}
? Without seeing your JSON2Apex class it's hard to figure out what Apex is expecting from your JSON.