Rest class :


global with sharing class GSSRestResourceChatter{

    global static String doPost(){
        List<ChatterDTO> fieldParsers = (List<ChatterDTO>)JSON.deserialize(

        System.debug('REST Context>>>>>>>>>>>'+RestContext.request.requestBody.tostring());

     // do something   


    global class ChatterDTO{
        public String ParentId{ get; set; }
        public String Body { get; set; }


Test class:

private class Test_GSSRestResourceChatter {
static testmethod void testGSSRestResourceChatter(){

 Account a = new Account(Name='Tester', 
        Account_Group__c = 'Sold To Party'
        insert a;

System.debug('accountid>>>>>' +a.Id);

        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();
        String jsonm ='[{"Some String"}]';
        req.requestURI = 'https://ap2.salesforce.com/services/apexrest/uhb/sdefs/'; 
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(jsonm);
        RestContext.request = req;
        RestContext.response = res;    
        GSSRestResourceChatter.ChatterDTO thisChatter = GSSRestResourceChatter.doPost();
       // System.assert(thisChatter!=null);
      System.assertEquals(thisChatter.ParentId, String.valueOf(a.Id));



I am getting error while saving the test class as

Compile Error: Illegal assignment from String to GSSRestResourceChatter.ChatterDTO at line 23 column 43

Please help me to sort out the error

  • What is actually returning the doPost() method? A string containing some sort of JSON serialization of a ChatterDTO object? If not you can assign ChatterDTO with a Object.valueOf of a String value Dec 31, 2015 at 10:07
  • doPost() method returns String . Yes serialization has been done for ChatterDTO object @Enreeco Dec 31, 2015 at 10:14
  • Now on line 23 use "GSSRestResourceChatter.ChatterDTO thisChatter = (GSSRestResourceChatter.ChatterDTO)JSON.deserialize(GSSRestResourceChatter.doPost()); ... this should work! Dec 31, 2015 at 10:16
  • JSON.deserialize is done in doPost method. Dec 31, 2015 at 10:22
  • The doPost() method returns a String and not a ChatterDTO object Dec 31, 2015 at 10:23

1 Answer 1


The problem was the fact that the doPost() method is not returning a ChatterDTO object

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .