1

I have this string s1 :

{"iss":"backend","nbf":499071708,"iat":1499071708,"exp":2499071708,"Server":{"Version":"1.0","Identity":"backend"},"Data":{"ContentList":["AzEuMFveOpUnBpFTJ5yYdqdZxJs=","AzEuMCTwj+JAzuZXsYDqiJ/od5Y=","AzEuMO8qfFMY5Q2H8ooj3bhUBB8=","AzEuMCUDXAbCjom1OQI+DzaFJnw=","AzEuMG97HAvirlTWsUCQUcXYge8=","AzEuMOIWd2Wq8hjdckeZr7wiiyA=","AzEuMEnR2z8WixFoPLbqonDNw+c=","AzEuMCB5BdoE/jXg1PyM9nCzqMA=","AzEuMF/bqXDosIqrsclbXOTtGi0=","AzEuMB3w9Kr8DCuIvbUVETS3d2I=","AzEuMMJ4nby5baP354yZdtPBZSk=","AzEuMOreiPhBQb9/zwrkT9swPnk="],"KeyId":"RV1XNapXLxELLUquNGFLdj1uFSRa3/GmgeCePj7DcUg=","CheckSum":"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="},"ResponseCode":"SUCCESS","Date":"2017-07-03T08:48:28.142Z"}

And I am using this function (Map < String,Object >)JSON.deserializeUntyped(s1);

In the Content List there are 12 words but when I deserialize all the string I am receiving in the Content List only 10 word and three points (...)

It is the deserialized string s1

 {Data={CheckSum=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=, ContentList=(AzEuMFveOpUnBpFTJ5yYdqdZxJs=, AzEuMCTwj+JAzuZXsYDqiJ/od5Y=, AzEuMO8qfFMY5Q2H8ooj3bhUBB8=, AzEuMCUDXAbCjom1OQI+DzaFJnw=, AzEuMG97HAvirlTWsUCQUcXYge8=, AzEuMOIWd2Wq8hjdckeZr7wiiyA=, AzEuMEnR2z8WixFoPLbqonDNw+c=, AzEuMCB5BdoE/jXg1PyM9nCzqMA=, AzEuMF/bqXDosIqrsclbXOTtGi0=, AzEuMB3w9Kr8DCuIvbUVETS3d2I=, ...), KeyId=RV1XNapXLxELLUquNGFLdj1uFSRa3/GmgeCePj7DcUg=}, Date=2017-07-03T08:48:28.142Z, ResponseCode=SUCCESS, Server={Identity=backend, Version=1.0}, exp=2499071708, iat=1499071708, iss=backend, nbf=499071708}

It is the problem :

enter image description here

Can you help me ? , I don't understand why I am losing words from the Content List which is in the Data of the string

Here you can see the object that I would like to receive :

enter image description here

And here you can see the object that I received :

enter image description here

Thank you

  • do you have that dots in debug log if so, that is normal behavior, as debug log shows not whole, but only few elements of collection, and for rest of them dots are printed? did you try to save it to any text field, that have enough length to store content ? – Oleksandr Berehovskyi Jul 3 '17 at 11:35
  • It is not only in the debug log , like you can see there is enougth space in the debug log because it is printing the others parts of the string , I am losing data only from the Conten List which is in the Data of the String , AzEuMB3w9Kr8DCuIvbUVETS3d2I=, ...), KeyId=RV – Raphym Jul 3 '17 at 11:39
  • 1
    It's the debug logs doing that; you'd want to iterate over the list and debug all the values to prove to yourself that they are there. – sfdcfox Jul 3 '17 at 13:15
  • ... with the debug logs doing that so a massive collection doesn't consume a lot of log space; you just get the first 10 (?) items. To see all the data JSON.serializePretty the map. – Keith C Jul 3 '17 at 13:22
  • no it is not the debug, to prove it, I have selected the Content List Of the Data and I added a test word to check what you said and its printed the word test; Here you can see the string which is the Content List of the Data from the precedent string: (AzEuMO0HwK0qCGOEhYUZ0pV3+6k=, AzEuMEM/+qE8XALHY5Fb+XASc0U=, AzEuMKGdG3DfKNhiM0k1AbtVhLw=, AzEuMAyARHr5+cQxNC2LkyC0RI8=, AzEuMIleJEKIbZGLGnD32i+2Gnc=, AzEuMKjXfSwzjGuAHR14NHKQ7cM=, AzEuMIWM1Eg7StxlYHeLsWGlUns=, AzEuMOME93cFukiY02qnF63theA=, AzEuMC/c6FYI/yXk+pHB2iK1jno=, AzEuMJwfVdZmcOPQ3AMi2BJofsw=, ...)test – Raphym Jul 3 '17 at 13:23
2

I am having a hard time following where you are seeing what. But I believe what you are seeing is in the debug logs the string being abbreviated.

You will be better served to create a class to deserialize into which can be easily generated by JSON2APEX and the class I generated is below:

//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

public class JSON2Apex {

    public class JSON2Apex {
        public String iss;
        public Integer nbf;
        public Integer iat;
        public Long exp;
        public Server Server;
        public Data Data;
        public String ResponseCode;
        public String Date;
    }

    public class Server {
        public String Version;
        public String Identity;
    }

    public class Data {
        public List<String> ContentList;
        public String KeyId;
        public String CheckSum;
    }


    public static JSON2Apex parse(String json) {
        return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
    }
}

Simply use the following code to deserialize:

JSON2Apex obj = JSON2APEX.parse([YOURSTRINGHERE]);

This will get you a nice object.

Now, back to your original way.

Your Key Data contains an object itself and thus when output in the debug logs directly will display the behavior you stated.

String t = '{"iss":"backend","nbf":499071708,"iat":1499071708,"exp":2499071708,"Server":{"Version":"1.0","Identity":"backend"},"Data":{"ContentList":["AzEuMFveOpUnBpFTJ5yYdqdZxJs=","AzEuMCTwj+JAzuZXsYDqiJ/od5Y=","AzEuMO8qfFMY5Q2H8ooj3bhUBB8=","AzEuMCUDXAbCjom1OQI+DzaFJnw=","AzEuMG97HAvirlTWsUCQUcXYge8=","AzEuMOIWd2Wq8hjdckeZr7wiiyA=","AzEuMEnR2z8WixFoPLbqonDNw+c=","AzEuMCB5BdoE/jXg1PyM9nCzqMA=","AzEuMF/bqXDosIqrsclbXOTtGi0=","AzEuMB3w9Kr8DCuIvbUVETS3d2I=","AzEuMMJ4nby5baP354yZdtPBZSk=","AzEuMOreiPhBQb9/zwrkT9swPnk="],"KeyId":"RV1XNapXLxELLUquNGFLdj1uFSRa3/GmgeCePj7DcUg=","CheckSum":"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="},"ResponseCode":"SUCCESS","Date":"2017-07-03T08:48:28.142Z"}';
Map<String,Object> tmp = (Map<String,Object>)json.deserializeUntyped(t);

System.debug(tmp.get('Data'));

07:19:47.26 (28506570)|USER_DEBUG|[11]|DEBUG|{CheckSum=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=, ContentList=(AzEuMFveOpUnBpFTJ5yYdqdZxJs=, AzEuMCTwj+JAzuZXsYDqiJ/od5Y=, AzEuMO8qfFMY5Q2H8ooj3bhUBB8=, AzEuMCUDXAbCjom1OQI+DzaFJnw=, AzEuMG97HAvirlTWsUCQUcXYge8=, AzEuMOIWd2Wq8hjdckeZr7wiiyA=, AzEuMEnR2z8WixFoPLbqonDNw+c=, AzEuMCB5BdoE/jXg1PyM9nCzqMA=, AzEuMF/bqXDosIqrsclbXOTtGi0=, AzEuMB3w9Kr8DCuIvbUVETS3d2I=, ...), KeyId=RV1XNapXLxELLUquNGFLdj1uFSRa3/GmgeCePj7DcUg=}

The following code however shows how to deserialize it and debug all the value proving that the ... that you were seeing is a function of the abbreviation. Why you are seeing it actually stored in your SF Object I cannot answer without seeing your code.

The follow shows the output as you would expect with all values (crude but works):

String t = '{"iss":"backend","nbf":499071708,"iat":1499071708,"exp":2499071708,"Server":{"Version":"1.0","Identity":"backend"},"Data":{"ContentList":["AzEuMFveOpUnBpFTJ5yYdqdZxJs=","AzEuMCTwj+JAzuZXsYDqiJ/od5Y=","AzEuMO8qfFMY5Q2H8ooj3bhUBB8=","AzEuMCUDXAbCjom1OQI+DzaFJnw=","AzEuMG97HAvirlTWsUCQUcXYge8=","AzEuMOIWd2Wq8hjdckeZr7wiiyA=","AzEuMEnR2z8WixFoPLbqonDNw+c=","AzEuMCB5BdoE/jXg1PyM9nCzqMA=","AzEuMF/bqXDosIqrsclbXOTtGi0=","AzEuMB3w9Kr8DCuIvbUVETS3d2I=","AzEuMMJ4nby5baP354yZdtPBZSk=","AzEuMOreiPhBQb9/zwrkT9swPnk="],"KeyId":"RV1XNapXLxELLUquNGFLdj1uFSRa3/GmgeCePj7DcUg=","CheckSum":"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="},"ResponseCode":"SUCCESS","Date":"2017-07-03T08:48:28.142Z"}';
Map<String,Object> tmp = (Map<String,Object>)json.deserializeUntyped(t);

for(String key : tmp.keySet()){
    if(key != 'Data') {
        System.debug('Key: ' + key + ' - Value: ' + tmp.get(key));
    }else{
        String dataString = json.serialize(tmp.get(key));
        Map<String,Object> dataValues = (Map<String,Object>)json.deserializeUntyped(dataString);
        for(String dataKey : dataValues.keySet()){
            if(dataKey == 'ContentList'){
                object[] cl = (object[])dataValues.get(dataKey);
                for(object listItem : cl){
                    System.debug('Content List Item: ' + listItem);
                }
            }else {
                System.debug('Data Key: ' + dataKey + ' - Data Value: ' + dataValues.get(dataKey));
            }
        }
    }
}

Output

07:13:19.21 (22738131)|USER_DEBUG|[13]|DEBUG|Key: iss - Value: backend

07:13:19.21 (22911886)|USER_DEBUG|[13]|DEBUG|Key: nbf - Value: 499071708

07:13:19.21 (23068383)|USER_DEBUG|[13]|DEBUG|Key: iat - Value: 14990717080

07:13:19.21 (23174679)|USER_DEBUG|[13]|DEBUG|Key: exp - Value: 2499071708

07:13:19.21 (23282582)|USER_DEBUG|[13]|DEBUG|Key: Server - Value: {Identity=backend, Version=1.0}

07:13:19.21 (24385363)|USER_DEBUG|[24]|DEBUG|Data Key: CheckSum - Data Value: 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=

07:13:19.21 (24497528)|USER_DEBUG|[24]|DEBUG|Data Key: KeyId - Data Value: RV1XNapXLxELLUquNGFLdj1uFSRa3/GmgeCePj7DcUg=

07:13:19.21 (24725499)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMFveOpUnBpFTJ5yYdqdZxJs=

07:13:19.21 (24807108)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMCTwj+JAzuZXsYDqiJ/od5Y=

07:13:19.21 (24883908)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMO8qfFMY5Q2H8ooj3bhUBB8=

07:13:19.21 (24959225)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMCUDXAbCjom1OQI+DzaFJnw=

07:13:19.21 (25034162)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMG97HAvirlTWsUCQUcXYge8=

07:13:19.21 (25107635)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMOIWd2Wq8hjdckeZr7wiiyA=

07:13:19.21 (25180741)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMEnR2z8WixFoPLbqonDNw+c=

07:13:19.21 (25253642)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMCB5BdoE/jXg1PyM9nCzqMA=

07:13:19.21 (25327031)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMF/bqXDosIqrsclbXOTtGi0=

07:13:19.21 (25404523)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMB3w9Kr8DCuIvbUVETS3d2I=

07:13:19.21 (25483266)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMMJ4nby5baP354yZdtPBZSk=

07:13:19.21 (25561852)|USER_DEBUG|[21]|DEBUG|Content List Item: AzEuMOreiPhBQb9/zwrkT9swPnk=

07:13:19.21 (25699372)|USER_DEBUG|[13]|DEBUG|Key: ResponseCode - Value: SUCCESS

07:13:19.21 (25792186)|USER_DEBUG|[13]|DEBUG|Key: Date - Value: 2017-07-03T08:48:28.142Z

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.