JSON DeSerialization Help?Write a generic JSON-serializable Parameters class without hitting “Apex Type unsupported in JSON: Object”APEX ENUM Serialize to and Deserialize from JSONJSON and escaped double quotedeserializing JSON returns a null objectJSON deserialize into wrapper class errorsJSON String test classJSON: Cannot deserialize instance of date from VALUE_STRINGSystem.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set while deseriliasing json PayloadSalesforce REST JSON not getting serialized properly?How to deserialize my json result?

What to do if SUS scores contradict qualitative feedback?

Does SQL Server allow (make visible) DDL inside a transaction to the transaction prior to commit?

Is it possible to create different colors in rocket exhaust?

Non-deterministic Finite Automata | Sipser Example 1.16

declared variable inside void setup is forgotten in void loop

Anabelian geometry ~ higher category theory

Are there any established rules for splitting books into parts, chapters, sections etc?

Formal Definition of Dot Product

Forgoing Enlightenment

Can't find the release for this wiring harness connector

Why do I get two different answers when solving for arclength?

Why was Thor doubtful about his worthiness to Mjolnir?

Smallest Guaranteed hash collision cycle length

What information do scammers need to withdraw money from an account?

What are the implications of the new alleged key recovery attack preprint on SIMON?

How can I answer high-school writing prompts without sounding weird and fake?

How exactly does artificial gravity work?

Would an 8% reduction in drag outweigh the weight addition from this custom CFD-tested winglet?

What makes "quality" analog AV cables better than cheap cables?

Tikz draw contour without some edges, and fill

Is Germany still exporting arms to countries involved in Yemen?

Jesus' words on the Jews

what does a native speaker say when he wanted to leave his work?

How does emacs `shell-mode` know to prompt for sudo?



JSON DeSerialization Help?


Write a generic JSON-serializable Parameters class without hitting “Apex Type unsupported in JSON: Object”APEX ENUM Serialize to and Deserialize from JSONJSON and escaped double quotedeserializing JSON returns a null objectJSON deserialize into wrapper class errorsJSON String test classJSON: Cannot deserialize instance of date from VALUE_STRINGSystem.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set while deseriliasing json PayloadSalesforce REST JSON not getting serialized properly?How to deserialize my json result?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am currently working on an integration with other systems and I have the JSON coming back in the below format.




"searchDocumentsResponse":
"documentsIndexInfo": [

"contentElementsInfo":
"fileName": "test.pdf",
"fileSize": 1010694,
"indexNumber": 0,
"mimeType": "application/pdf"
,
"guid": "123456789-1234-1234-1234-92393300000",
"majorVersion": 1,
"minorVersion": 0,
"objectStore": "09876543212-1234-4B53-8CC5-469444E92456",
"pathName": "",
"properties": [

"multiValue": false,
"name": "Document_Type",
"type": "STRING",
"value": "TEST"
,

"multiValue": false,
"name": "ScanTMSTMP",
"type": "DATE",
"value": "5/16/1920"
,

"multiValue": false,
"name": "f_DocNumber",
"type": "STRING",
"value": ""
,

"multiValue": false,
"name": "MimeType",
"type": "STRING",
"value": "application/pdf"
,

"multiValue": false,
"name": "DateCreated",
"type": "DATE",
"value": "5/31/2018"

]


],
"numDocObjectsFound": 1,
"numDocObjectsReturned": 1,
"responseStatus":
"code": "OK",
"message": ""
,
"startingDocObject": 0




And I am trying to parse the response like below:



public class DocumentRetrievalResponse 

public SearchDocumentsResponse searchDocumentsResponse get;set;
public cecDocumentRetrievalResponse()


public class SearchDocumentsResponse
public String numDocObjectsFound get;set;
public String numDocObjectsReturned get;set;
public ResponseStatus responseStatus get;set;
public String startingDocObject get;set;
public List<DocumentsIndexInfo> documentsIndexInfo get;set; documentsIndexInfo = new List<DocumentsIndexInfo>();
public SearchDocumentsResponse()



public class ResponseStatus
public String code get;set;
public String messageget;set;
public ResponseStatus()




public class DocumentsIndexInfo
public String guidget;set; guid = null;
public Integer majorVersionget;set; majorVersion = 0;
public Integer minorVersionget;set;minorVersion = 0;
public String objectStoreget;set;objectStore = null;
public String pathNameget;set; pathName = null;
public ContentElementsInfo contentElementsInfo get;set;
public List<Properties> propertiesget;set; properties = new List<Properties>();



public class ContentElementsInfo
public String fileNameget;set; fileName = null;
public Integer fileSizeget;set; fileSize = 0;
public Integer indexNumberget;set; indexNumber = 0;
public String mimeTypeget;set;mimeType = null;



public class Properties
public String name get;set;
public String value get;set;
public String type get;set;
public String multiValue get;set; multiValue = 'false';





And to deserialize, I have the below lines:



System.Type resultType = System.Type.forName('DocumentRetrievalResponse');
DocumentRetrievalResponse deserializeResults =
(DocumentRetrievalResponse)JSON.deserialize(result, resultType);


When I run it, I get the JSON Exception as below. I might be overthinking and missing something here. Any help on this is appreciated.




FATAL_ERROR System.JSONException: Expected DocumentRetrievalResponse.ContentElementsInfo but found [line:1, column:2444]




PS: if I comment the declaration public ContentElementsInfo contentElementsInfo get;set;, the deserialize happens fine but without ContentElementsInfo.










share|improve this question



















  • 1





    Unless its a typo, you have an invalid constructor here public cecDocumentRetrievalResponse(). Is this the only error you are getting? With a minimal code, if reproduced, I don't see an issue here.

    – Jayant Das
    May 8 at 20:56











  • Your model syntax is awkward, as you have multiple instance initializers (e.g. documentsIndexInfo = new List<DocumentsIndexInfo>();) in several of your class definitions. They do nothing in the context of deserialization and can simply be removed. In addition, the documentation recommends you reserve use of initializers for complex logic.

    – Adrian Larson
    May 8 at 20:59












  • N.B. attribute multiValue sb declared as Boolean; majorVersion and minorVersion as Integer

    – cropredy
    May 8 at 21:00

















1















I am currently working on an integration with other systems and I have the JSON coming back in the below format.




"searchDocumentsResponse":
"documentsIndexInfo": [

"contentElementsInfo":
"fileName": "test.pdf",
"fileSize": 1010694,
"indexNumber": 0,
"mimeType": "application/pdf"
,
"guid": "123456789-1234-1234-1234-92393300000",
"majorVersion": 1,
"minorVersion": 0,
"objectStore": "09876543212-1234-4B53-8CC5-469444E92456",
"pathName": "",
"properties": [

"multiValue": false,
"name": "Document_Type",
"type": "STRING",
"value": "TEST"
,

"multiValue": false,
"name": "ScanTMSTMP",
"type": "DATE",
"value": "5/16/1920"
,

"multiValue": false,
"name": "f_DocNumber",
"type": "STRING",
"value": ""
,

"multiValue": false,
"name": "MimeType",
"type": "STRING",
"value": "application/pdf"
,

"multiValue": false,
"name": "DateCreated",
"type": "DATE",
"value": "5/31/2018"

]


],
"numDocObjectsFound": 1,
"numDocObjectsReturned": 1,
"responseStatus":
"code": "OK",
"message": ""
,
"startingDocObject": 0




And I am trying to parse the response like below:



public class DocumentRetrievalResponse 

public SearchDocumentsResponse searchDocumentsResponse get;set;
public cecDocumentRetrievalResponse()


public class SearchDocumentsResponse
public String numDocObjectsFound get;set;
public String numDocObjectsReturned get;set;
public ResponseStatus responseStatus get;set;
public String startingDocObject get;set;
public List<DocumentsIndexInfo> documentsIndexInfo get;set; documentsIndexInfo = new List<DocumentsIndexInfo>();
public SearchDocumentsResponse()



public class ResponseStatus
public String code get;set;
public String messageget;set;
public ResponseStatus()




public class DocumentsIndexInfo
public String guidget;set; guid = null;
public Integer majorVersionget;set; majorVersion = 0;
public Integer minorVersionget;set;minorVersion = 0;
public String objectStoreget;set;objectStore = null;
public String pathNameget;set; pathName = null;
public ContentElementsInfo contentElementsInfo get;set;
public List<Properties> propertiesget;set; properties = new List<Properties>();



public class ContentElementsInfo
public String fileNameget;set; fileName = null;
public Integer fileSizeget;set; fileSize = 0;
public Integer indexNumberget;set; indexNumber = 0;
public String mimeTypeget;set;mimeType = null;



public class Properties
public String name get;set;
public String value get;set;
public String type get;set;
public String multiValue get;set; multiValue = 'false';





And to deserialize, I have the below lines:



System.Type resultType = System.Type.forName('DocumentRetrievalResponse');
DocumentRetrievalResponse deserializeResults =
(DocumentRetrievalResponse)JSON.deserialize(result, resultType);


When I run it, I get the JSON Exception as below. I might be overthinking and missing something here. Any help on this is appreciated.




FATAL_ERROR System.JSONException: Expected DocumentRetrievalResponse.ContentElementsInfo but found [line:1, column:2444]




PS: if I comment the declaration public ContentElementsInfo contentElementsInfo get;set;, the deserialize happens fine but without ContentElementsInfo.










share|improve this question



















  • 1





    Unless its a typo, you have an invalid constructor here public cecDocumentRetrievalResponse(). Is this the only error you are getting? With a minimal code, if reproduced, I don't see an issue here.

    – Jayant Das
    May 8 at 20:56











  • Your model syntax is awkward, as you have multiple instance initializers (e.g. documentsIndexInfo = new List<DocumentsIndexInfo>();) in several of your class definitions. They do nothing in the context of deserialization and can simply be removed. In addition, the documentation recommends you reserve use of initializers for complex logic.

    – Adrian Larson
    May 8 at 20:59












  • N.B. attribute multiValue sb declared as Boolean; majorVersion and minorVersion as Integer

    – cropredy
    May 8 at 21:00













1












1








1








I am currently working on an integration with other systems and I have the JSON coming back in the below format.




"searchDocumentsResponse":
"documentsIndexInfo": [

"contentElementsInfo":
"fileName": "test.pdf",
"fileSize": 1010694,
"indexNumber": 0,
"mimeType": "application/pdf"
,
"guid": "123456789-1234-1234-1234-92393300000",
"majorVersion": 1,
"minorVersion": 0,
"objectStore": "09876543212-1234-4B53-8CC5-469444E92456",
"pathName": "",
"properties": [

"multiValue": false,
"name": "Document_Type",
"type": "STRING",
"value": "TEST"
,

"multiValue": false,
"name": "ScanTMSTMP",
"type": "DATE",
"value": "5/16/1920"
,

"multiValue": false,
"name": "f_DocNumber",
"type": "STRING",
"value": ""
,

"multiValue": false,
"name": "MimeType",
"type": "STRING",
"value": "application/pdf"
,

"multiValue": false,
"name": "DateCreated",
"type": "DATE",
"value": "5/31/2018"

]


],
"numDocObjectsFound": 1,
"numDocObjectsReturned": 1,
"responseStatus":
"code": "OK",
"message": ""
,
"startingDocObject": 0




And I am trying to parse the response like below:



public class DocumentRetrievalResponse 

public SearchDocumentsResponse searchDocumentsResponse get;set;
public cecDocumentRetrievalResponse()


public class SearchDocumentsResponse
public String numDocObjectsFound get;set;
public String numDocObjectsReturned get;set;
public ResponseStatus responseStatus get;set;
public String startingDocObject get;set;
public List<DocumentsIndexInfo> documentsIndexInfo get;set; documentsIndexInfo = new List<DocumentsIndexInfo>();
public SearchDocumentsResponse()



public class ResponseStatus
public String code get;set;
public String messageget;set;
public ResponseStatus()




public class DocumentsIndexInfo
public String guidget;set; guid = null;
public Integer majorVersionget;set; majorVersion = 0;
public Integer minorVersionget;set;minorVersion = 0;
public String objectStoreget;set;objectStore = null;
public String pathNameget;set; pathName = null;
public ContentElementsInfo contentElementsInfo get;set;
public List<Properties> propertiesget;set; properties = new List<Properties>();



public class ContentElementsInfo
public String fileNameget;set; fileName = null;
public Integer fileSizeget;set; fileSize = 0;
public Integer indexNumberget;set; indexNumber = 0;
public String mimeTypeget;set;mimeType = null;



public class Properties
public String name get;set;
public String value get;set;
public String type get;set;
public String multiValue get;set; multiValue = 'false';





And to deserialize, I have the below lines:



System.Type resultType = System.Type.forName('DocumentRetrievalResponse');
DocumentRetrievalResponse deserializeResults =
(DocumentRetrievalResponse)JSON.deserialize(result, resultType);


When I run it, I get the JSON Exception as below. I might be overthinking and missing something here. Any help on this is appreciated.




FATAL_ERROR System.JSONException: Expected DocumentRetrievalResponse.ContentElementsInfo but found [line:1, column:2444]




PS: if I comment the declaration public ContentElementsInfo contentElementsInfo get;set;, the deserialize happens fine but without ContentElementsInfo.










share|improve this question
















I am currently working on an integration with other systems and I have the JSON coming back in the below format.




"searchDocumentsResponse":
"documentsIndexInfo": [

"contentElementsInfo":
"fileName": "test.pdf",
"fileSize": 1010694,
"indexNumber": 0,
"mimeType": "application/pdf"
,
"guid": "123456789-1234-1234-1234-92393300000",
"majorVersion": 1,
"minorVersion": 0,
"objectStore": "09876543212-1234-4B53-8CC5-469444E92456",
"pathName": "",
"properties": [

"multiValue": false,
"name": "Document_Type",
"type": "STRING",
"value": "TEST"
,

"multiValue": false,
"name": "ScanTMSTMP",
"type": "DATE",
"value": "5/16/1920"
,

"multiValue": false,
"name": "f_DocNumber",
"type": "STRING",
"value": ""
,

"multiValue": false,
"name": "MimeType",
"type": "STRING",
"value": "application/pdf"
,

"multiValue": false,
"name": "DateCreated",
"type": "DATE",
"value": "5/31/2018"

]


],
"numDocObjectsFound": 1,
"numDocObjectsReturned": 1,
"responseStatus":
"code": "OK",
"message": ""
,
"startingDocObject": 0




And I am trying to parse the response like below:



public class DocumentRetrievalResponse 

public SearchDocumentsResponse searchDocumentsResponse get;set;
public cecDocumentRetrievalResponse()


public class SearchDocumentsResponse
public String numDocObjectsFound get;set;
public String numDocObjectsReturned get;set;
public ResponseStatus responseStatus get;set;
public String startingDocObject get;set;
public List<DocumentsIndexInfo> documentsIndexInfo get;set; documentsIndexInfo = new List<DocumentsIndexInfo>();
public SearchDocumentsResponse()



public class ResponseStatus
public String code get;set;
public String messageget;set;
public ResponseStatus()




public class DocumentsIndexInfo
public String guidget;set; guid = null;
public Integer majorVersionget;set; majorVersion = 0;
public Integer minorVersionget;set;minorVersion = 0;
public String objectStoreget;set;objectStore = null;
public String pathNameget;set; pathName = null;
public ContentElementsInfo contentElementsInfo get;set;
public List<Properties> propertiesget;set; properties = new List<Properties>();



public class ContentElementsInfo
public String fileNameget;set; fileName = null;
public Integer fileSizeget;set; fileSize = 0;
public Integer indexNumberget;set; indexNumber = 0;
public String mimeTypeget;set;mimeType = null;



public class Properties
public String name get;set;
public String value get;set;
public String type get;set;
public String multiValue get;set; multiValue = 'false';





And to deserialize, I have the below lines:



System.Type resultType = System.Type.forName('DocumentRetrievalResponse');
DocumentRetrievalResponse deserializeResults =
(DocumentRetrievalResponse)JSON.deserialize(result, resultType);


When I run it, I get the JSON Exception as below. I might be overthinking and missing something here. Any help on this is appreciated.




FATAL_ERROR System.JSONException: Expected DocumentRetrievalResponse.ContentElementsInfo but found [line:1, column:2444]




PS: if I comment the declaration public ContentElementsInfo contentElementsInfo get;set;, the deserialize happens fine but without ContentElementsInfo.







apex json deserialize parser






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 8 at 20:54









Adrian Larson

112k19123263




112k19123263










asked May 8 at 20:34









RajeshRajesh

3116




3116







  • 1





    Unless its a typo, you have an invalid constructor here public cecDocumentRetrievalResponse(). Is this the only error you are getting? With a minimal code, if reproduced, I don't see an issue here.

    – Jayant Das
    May 8 at 20:56











  • Your model syntax is awkward, as you have multiple instance initializers (e.g. documentsIndexInfo = new List<DocumentsIndexInfo>();) in several of your class definitions. They do nothing in the context of deserialization and can simply be removed. In addition, the documentation recommends you reserve use of initializers for complex logic.

    – Adrian Larson
    May 8 at 20:59












  • N.B. attribute multiValue sb declared as Boolean; majorVersion and minorVersion as Integer

    – cropredy
    May 8 at 21:00












  • 1





    Unless its a typo, you have an invalid constructor here public cecDocumentRetrievalResponse(). Is this the only error you are getting? With a minimal code, if reproduced, I don't see an issue here.

    – Jayant Das
    May 8 at 20:56











  • Your model syntax is awkward, as you have multiple instance initializers (e.g. documentsIndexInfo = new List<DocumentsIndexInfo>();) in several of your class definitions. They do nothing in the context of deserialization and can simply be removed. In addition, the documentation recommends you reserve use of initializers for complex logic.

    – Adrian Larson
    May 8 at 20:59












  • N.B. attribute multiValue sb declared as Boolean; majorVersion and minorVersion as Integer

    – cropredy
    May 8 at 21:00







1




1





Unless its a typo, you have an invalid constructor here public cecDocumentRetrievalResponse(). Is this the only error you are getting? With a minimal code, if reproduced, I don't see an issue here.

– Jayant Das
May 8 at 20:56





Unless its a typo, you have an invalid constructor here public cecDocumentRetrievalResponse(). Is this the only error you are getting? With a minimal code, if reproduced, I don't see an issue here.

– Jayant Das
May 8 at 20:56













Your model syntax is awkward, as you have multiple instance initializers (e.g. documentsIndexInfo = new List<DocumentsIndexInfo>();) in several of your class definitions. They do nothing in the context of deserialization and can simply be removed. In addition, the documentation recommends you reserve use of initializers for complex logic.

– Adrian Larson
May 8 at 20:59






Your model syntax is awkward, as you have multiple instance initializers (e.g. documentsIndexInfo = new List<DocumentsIndexInfo>();) in several of your class definitions. They do nothing in the context of deserialization and can simply be removed. In addition, the documentation recommends you reserve use of initializers for complex logic.

– Adrian Larson
May 8 at 20:59














N.B. attribute multiValue sb declared as Boolean; majorVersion and minorVersion as Integer

– cropredy
May 8 at 21:00





N.B. attribute multiValue sb declared as Boolean; majorVersion and minorVersion as Integer

– cropredy
May 8 at 21:00










1 Answer
1






active

oldest

votes


















4














You seem to have a typo in your class.



cecDocumentRetrievalResponse()


should be
DocumentRetrievalResponse()



If I use your same DocumentRetrievalResponse class, remove the cec and use your JSON I can run your lines and it works for me. I made no changes to your code.



String result = '"searchDocumentsResponse": "documentsIndexInfo": ["contentElementsInfo": "fileName": "test.pdf","fileSize": 1010694,"indexNumber": 0,"mimeType": "application/pdf","guid": "123456789-1234-1234-1234-92393300000","majorVersion": 1,"minorVersion": 0,"objectStore": "09876543212-1234-4B53-8CC5-469444E92456","pathName": "","properties": ["multiValue": false,"name": "Document_Type","type": "STRING","value": "TEST","multiValue": false,"name": "ScanTMSTMP","type": "DATE","value": "5/16/1920","multiValue": false,"name": "f_DocNumber","type": "STRING","value": "","multiValue": false,"name": "MimeType","type": "STRING","value": "application/pdf","multiValue": false,"name": "DateCreated","type": "DATE","value": "5/31/2018"] ],"numDocObjectsFound": 1,"numDocObjectsReturned": 1,"responseStatus": "code": "OK","message": "","startingDocObject": 0';
System.Type resultType = System.Type.forName('DocumentRetrievalResponse');

DocumentRetrievalResponse deserializeResults = (DocumentRetrievalResponse)JSON.deserialize(result, resultType);
System.debug('deserializeResults ' + deserializeResults.searchDocumentsResponse.documentsIndexInfo[0].contentElementsInfo.fileName);





share|improve this answer























  • Thank you so much for the help Jayant Das, Adrian Larson, Cropredy and Tad. As everyone rightly mentioned there was a typo and also removed unnecessary initializers. For the JSON example above, I was able to deserialize successfully.

    – Rajesh
    May 9 at 15:24











  • When I was checking for few more responses, I noticed that the 'contentElementsInfo' comes back as the List of object (sometimes). When I checked with the team who is exposing the service, they mentioned unfortunately they cannot make it as List always as they are getting such response from somewhere else which I do not have much information.

    – Rajesh
    May 9 at 15:26











  • That being said, I will have to deserialize based on the type of the 'contentElementsInfo'. So, it could be something like below: "contentElementsInfo" : ..... OR "contentElementsInfo" : [......., .....]

    – Rajesh
    May 9 at 15:26











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f261700%2fjson-deserialization-help%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














You seem to have a typo in your class.



cecDocumentRetrievalResponse()


should be
DocumentRetrievalResponse()



If I use your same DocumentRetrievalResponse class, remove the cec and use your JSON I can run your lines and it works for me. I made no changes to your code.



String result = '"searchDocumentsResponse": "documentsIndexInfo": ["contentElementsInfo": "fileName": "test.pdf","fileSize": 1010694,"indexNumber": 0,"mimeType": "application/pdf","guid": "123456789-1234-1234-1234-92393300000","majorVersion": 1,"minorVersion": 0,"objectStore": "09876543212-1234-4B53-8CC5-469444E92456","pathName": "","properties": ["multiValue": false,"name": "Document_Type","type": "STRING","value": "TEST","multiValue": false,"name": "ScanTMSTMP","type": "DATE","value": "5/16/1920","multiValue": false,"name": "f_DocNumber","type": "STRING","value": "","multiValue": false,"name": "MimeType","type": "STRING","value": "application/pdf","multiValue": false,"name": "DateCreated","type": "DATE","value": "5/31/2018"] ],"numDocObjectsFound": 1,"numDocObjectsReturned": 1,"responseStatus": "code": "OK","message": "","startingDocObject": 0';
System.Type resultType = System.Type.forName('DocumentRetrievalResponse');

DocumentRetrievalResponse deserializeResults = (DocumentRetrievalResponse)JSON.deserialize(result, resultType);
System.debug('deserializeResults ' + deserializeResults.searchDocumentsResponse.documentsIndexInfo[0].contentElementsInfo.fileName);





share|improve this answer























  • Thank you so much for the help Jayant Das, Adrian Larson, Cropredy and Tad. As everyone rightly mentioned there was a typo and also removed unnecessary initializers. For the JSON example above, I was able to deserialize successfully.

    – Rajesh
    May 9 at 15:24











  • When I was checking for few more responses, I noticed that the 'contentElementsInfo' comes back as the List of object (sometimes). When I checked with the team who is exposing the service, they mentioned unfortunately they cannot make it as List always as they are getting such response from somewhere else which I do not have much information.

    – Rajesh
    May 9 at 15:26











  • That being said, I will have to deserialize based on the type of the 'contentElementsInfo'. So, it could be something like below: "contentElementsInfo" : ..... OR "contentElementsInfo" : [......., .....]

    – Rajesh
    May 9 at 15:26















4














You seem to have a typo in your class.



cecDocumentRetrievalResponse()


should be
DocumentRetrievalResponse()



If I use your same DocumentRetrievalResponse class, remove the cec and use your JSON I can run your lines and it works for me. I made no changes to your code.



String result = '"searchDocumentsResponse": "documentsIndexInfo": ["contentElementsInfo": "fileName": "test.pdf","fileSize": 1010694,"indexNumber": 0,"mimeType": "application/pdf","guid": "123456789-1234-1234-1234-92393300000","majorVersion": 1,"minorVersion": 0,"objectStore": "09876543212-1234-4B53-8CC5-469444E92456","pathName": "","properties": ["multiValue": false,"name": "Document_Type","type": "STRING","value": "TEST","multiValue": false,"name": "ScanTMSTMP","type": "DATE","value": "5/16/1920","multiValue": false,"name": "f_DocNumber","type": "STRING","value": "","multiValue": false,"name": "MimeType","type": "STRING","value": "application/pdf","multiValue": false,"name": "DateCreated","type": "DATE","value": "5/31/2018"] ],"numDocObjectsFound": 1,"numDocObjectsReturned": 1,"responseStatus": "code": "OK","message": "","startingDocObject": 0';
System.Type resultType = System.Type.forName('DocumentRetrievalResponse');

DocumentRetrievalResponse deserializeResults = (DocumentRetrievalResponse)JSON.deserialize(result, resultType);
System.debug('deserializeResults ' + deserializeResults.searchDocumentsResponse.documentsIndexInfo[0].contentElementsInfo.fileName);





share|improve this answer























  • Thank you so much for the help Jayant Das, Adrian Larson, Cropredy and Tad. As everyone rightly mentioned there was a typo and also removed unnecessary initializers. For the JSON example above, I was able to deserialize successfully.

    – Rajesh
    May 9 at 15:24











  • When I was checking for few more responses, I noticed that the 'contentElementsInfo' comes back as the List of object (sometimes). When I checked with the team who is exposing the service, they mentioned unfortunately they cannot make it as List always as they are getting such response from somewhere else which I do not have much information.

    – Rajesh
    May 9 at 15:26











  • That being said, I will have to deserialize based on the type of the 'contentElementsInfo'. So, it could be something like below: "contentElementsInfo" : ..... OR "contentElementsInfo" : [......., .....]

    – Rajesh
    May 9 at 15:26













4












4








4







You seem to have a typo in your class.



cecDocumentRetrievalResponse()


should be
DocumentRetrievalResponse()



If I use your same DocumentRetrievalResponse class, remove the cec and use your JSON I can run your lines and it works for me. I made no changes to your code.



String result = '"searchDocumentsResponse": "documentsIndexInfo": ["contentElementsInfo": "fileName": "test.pdf","fileSize": 1010694,"indexNumber": 0,"mimeType": "application/pdf","guid": "123456789-1234-1234-1234-92393300000","majorVersion": 1,"minorVersion": 0,"objectStore": "09876543212-1234-4B53-8CC5-469444E92456","pathName": "","properties": ["multiValue": false,"name": "Document_Type","type": "STRING","value": "TEST","multiValue": false,"name": "ScanTMSTMP","type": "DATE","value": "5/16/1920","multiValue": false,"name": "f_DocNumber","type": "STRING","value": "","multiValue": false,"name": "MimeType","type": "STRING","value": "application/pdf","multiValue": false,"name": "DateCreated","type": "DATE","value": "5/31/2018"] ],"numDocObjectsFound": 1,"numDocObjectsReturned": 1,"responseStatus": "code": "OK","message": "","startingDocObject": 0';
System.Type resultType = System.Type.forName('DocumentRetrievalResponse');

DocumentRetrievalResponse deserializeResults = (DocumentRetrievalResponse)JSON.deserialize(result, resultType);
System.debug('deserializeResults ' + deserializeResults.searchDocumentsResponse.documentsIndexInfo[0].contentElementsInfo.fileName);





share|improve this answer













You seem to have a typo in your class.



cecDocumentRetrievalResponse()


should be
DocumentRetrievalResponse()



If I use your same DocumentRetrievalResponse class, remove the cec and use your JSON I can run your lines and it works for me. I made no changes to your code.



String result = '"searchDocumentsResponse": "documentsIndexInfo": ["contentElementsInfo": "fileName": "test.pdf","fileSize": 1010694,"indexNumber": 0,"mimeType": "application/pdf","guid": "123456789-1234-1234-1234-92393300000","majorVersion": 1,"minorVersion": 0,"objectStore": "09876543212-1234-4B53-8CC5-469444E92456","pathName": "","properties": ["multiValue": false,"name": "Document_Type","type": "STRING","value": "TEST","multiValue": false,"name": "ScanTMSTMP","type": "DATE","value": "5/16/1920","multiValue": false,"name": "f_DocNumber","type": "STRING","value": "","multiValue": false,"name": "MimeType","type": "STRING","value": "application/pdf","multiValue": false,"name": "DateCreated","type": "DATE","value": "5/31/2018"] ],"numDocObjectsFound": 1,"numDocObjectsReturned": 1,"responseStatus": "code": "OK","message": "","startingDocObject": 0';
System.Type resultType = System.Type.forName('DocumentRetrievalResponse');

DocumentRetrievalResponse deserializeResults = (DocumentRetrievalResponse)JSON.deserialize(result, resultType);
System.debug('deserializeResults ' + deserializeResults.searchDocumentsResponse.documentsIndexInfo[0].contentElementsInfo.fileName);






share|improve this answer












share|improve this answer



share|improve this answer










answered May 8 at 20:56









TadTad

1359




1359












  • Thank you so much for the help Jayant Das, Adrian Larson, Cropredy and Tad. As everyone rightly mentioned there was a typo and also removed unnecessary initializers. For the JSON example above, I was able to deserialize successfully.

    – Rajesh
    May 9 at 15:24











  • When I was checking for few more responses, I noticed that the 'contentElementsInfo' comes back as the List of object (sometimes). When I checked with the team who is exposing the service, they mentioned unfortunately they cannot make it as List always as they are getting such response from somewhere else which I do not have much information.

    – Rajesh
    May 9 at 15:26











  • That being said, I will have to deserialize based on the type of the 'contentElementsInfo'. So, it could be something like below: "contentElementsInfo" : ..... OR "contentElementsInfo" : [......., .....]

    – Rajesh
    May 9 at 15:26

















  • Thank you so much for the help Jayant Das, Adrian Larson, Cropredy and Tad. As everyone rightly mentioned there was a typo and also removed unnecessary initializers. For the JSON example above, I was able to deserialize successfully.

    – Rajesh
    May 9 at 15:24











  • When I was checking for few more responses, I noticed that the 'contentElementsInfo' comes back as the List of object (sometimes). When I checked with the team who is exposing the service, they mentioned unfortunately they cannot make it as List always as they are getting such response from somewhere else which I do not have much information.

    – Rajesh
    May 9 at 15:26











  • That being said, I will have to deserialize based on the type of the 'contentElementsInfo'. So, it could be something like below: "contentElementsInfo" : ..... OR "contentElementsInfo" : [......., .....]

    – Rajesh
    May 9 at 15:26
















Thank you so much for the help Jayant Das, Adrian Larson, Cropredy and Tad. As everyone rightly mentioned there was a typo and also removed unnecessary initializers. For the JSON example above, I was able to deserialize successfully.

– Rajesh
May 9 at 15:24





Thank you so much for the help Jayant Das, Adrian Larson, Cropredy and Tad. As everyone rightly mentioned there was a typo and also removed unnecessary initializers. For the JSON example above, I was able to deserialize successfully.

– Rajesh
May 9 at 15:24













When I was checking for few more responses, I noticed that the 'contentElementsInfo' comes back as the List of object (sometimes). When I checked with the team who is exposing the service, they mentioned unfortunately they cannot make it as List always as they are getting such response from somewhere else which I do not have much information.

– Rajesh
May 9 at 15:26





When I was checking for few more responses, I noticed that the 'contentElementsInfo' comes back as the List of object (sometimes). When I checked with the team who is exposing the service, they mentioned unfortunately they cannot make it as List always as they are getting such response from somewhere else which I do not have much information.

– Rajesh
May 9 at 15:26













That being said, I will have to deserialize based on the type of the 'contentElementsInfo'. So, it could be something like below: "contentElementsInfo" : ..... OR "contentElementsInfo" : [......., .....]

– Rajesh
May 9 at 15:26





That being said, I will have to deserialize based on the type of the 'contentElementsInfo'. So, it could be something like below: "contentElementsInfo" : ..... OR "contentElementsInfo" : [......., .....]

– Rajesh
May 9 at 15:26

















draft saved

draft discarded
















































Thanks for contributing an answer to Salesforce Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f261700%2fjson-deserialization-help%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?