You need to sign in to do that
Don't have an account?
Showing error when i run test class.
Hi there,
I am getting this error at the time of running test class at the below line.
list<User> users = (list<User>) JSON.deserialize(newUsersJson, List<User>.class);
Error: malformed json exception.expected [ in salesforce at the begning of the list/set
any help can be appreciable.
Thanks
I am getting this error at the time of running test class at the below line.
list<User> users = (list<User>) JSON.deserialize(newUsersJson, List<User>.class);
Error: malformed json exception.expected [ in salesforce at the begning of the list/set
any help can be appreciable.
Thanks
After insert user in userList in a test class, you have to serialize this list
String userDetails = JSON.serialize(userList);
After that pass userDetails to your class method for running
list<User> users = (list<User>) JSON.deserialize(newUsersJson, List<User>.class);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
All Answers
As mentioned in error there is some issue with format of json. Try online tool https://jsonlint.com (https://jsonlint.com/) to validate your json then process.
After insert user in userList in a test class, you have to serialize this list
String userDetails = JSON.serialize(userList);
After that pass userDetails to your class method for running
list<User> users = (list<User>) JSON.deserialize(newUsersJson, List<User>.class);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Greetings to you!
- The problem is that you're trying to deserialize a JSON object (not an array) into a list
- I sharing a reference link for the same problem :
https://developer.salesforce.com/forums/?id=906F000000090abIAA
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.