I have a List of Schema.SObjectfield and I want to convert it to String.

I am getting below error.

System.JSONException: Apex Type unsupported in JSON: Schema.SObjectField

Here is my approach.

  public string jsondata{get;set;}

  List<Schema.SObjectField> fieldschema = new List<Schema.SObjectField>();

    for(Schema.SObjectField sfield : fieldMap.Values()) {

     jsondata = JSON.serialize(fieldschema);
 jsonstring = (List<jsonvalue>) System.JSON.deserialize(jsondata , List<jsonvalue>.class);

can someone please let me know where is wrong in my approach or how to handle it?

1 Answer 1


You can't serialize SObjectField, as the error says, but it's easy to get the value as a String:

public string jsondata{get;set;}
List<String> fieldschema = new List<String>();

for(Schema.SObjectField sfield : fieldMap.Values()) {

jsondata = JSON.serialize(fieldschema);

You can also use the keyset values:

fieldSchema = new List<String>(fieldMap.keySet());
  • I am getting this error with this code after execution in runtime. System.JSONException: Expected ABV_GenerateXMLs.jsonvalue but found "Id" at [line:1, column:2] Error is in expression '{!getFieldsPicklist}' in page generatexmls: Class.System.JSON.deserialize: line 15, column 1 Jun 16, 2018 at 15:16

You must log in to answer this question.

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