I'm doing a REST API call to get the global value set and trying to deserialize the JSON result to get the picklist values in a List.
Here is the JSON:
{
"size": 1,
"totalSize": 1,
"done": true,
"queryLocator": null,
"entityTypeName": "GlobalValueSet",
"records": [
{
"attributes": {
"type": "GlobalValueSet",
"url": "/services/data/v53.0/tooling/sobjects/GlobalValueSet/0Nt59000000AAAAAAA"
},
"Metadata": {
"customValue": [
{
"color": null,
"default": false,
"description": null,
"isActive": null,
"label": "USA",
"urls": null,
"valueName": "USA"
},
{
"color": null,
"default": false,
"description": null,
"isActive": null,
"label": "Canada",
"urls": null,
"valueName": "Canada"
}
],
"description": null,
"masterLabel": "Countries",
"sorted": false,
"urls": null
},
"Id": "0Nt59000000AAAAAAA"
}
]
}
I need help in fixing the error and also how to get valueNames in a List
Error: System.JSONException: Malformed JSON: Expected '{' at the beginning of an object.
Here is what I have tried so far:
Wrapper:
Here is my original wrapper that covers all blocks but still throwing the same error.
public class GlobalValueSetWrapper{
public Integer size;
public Integer totalSize;
public boolean done;
public QueryLocator queryLocator;
public String entityTypeName;
public List<Records> records;
class QueryLocator {
}
class Records {
public Attributes attributes;
public Metadata Metadata;
public String Id;
}
class Attributes {
public String type;
public String url;
}
class Metadata {
public List<CustomValue> customValue;
public Description description;
public String masterLabel;
public boolean sorted;
public URLs urls;
}
class CustomValue {
public Color color;
public boolean default;
public Description description;
public IsActive isActive;
public String label;
public URLs urls;
public String valueName;
}
class Color {
}
class Description {
}
class IsActive {
}
class URLs {
}
public static GlobalValueSetWrapper parse(String json){
return (GlobalValueSetWrapper) System.JSON.deserialize(json, GlobalValueSetWrapper.class);
}
Class:
//calling API to get the JSON result
HttpResponse res = GlobalValueSetAPIHandler.getResponse('Countries');
GlobalValueSetWrapper wrapper = (GlobalValueSetWrapper) JSON.deserialize(res.getBody(), GlobalValueSetWrapper.class);
res.getBody()
is the JSON you expect? Is it a string that starts with a{
?