Questions tagged [deserialize]

The tag has no usage guidance, but it has a tag wiki.

Filter by
Sorted by
Tagged with
19
votes
1answer
813 views

Aura vs Apex - Deserialization and Interface discrepancy (Major rewrite with git repo)

Question rewritten and complete example code provided I am trying to write test methods for an aura implementation but am running into a roadblock where the JSON serialization/deserialization between ...
14
votes
1answer
41k views

How to deserialize a JSON String to Apex

How can I deserialize this json object: { "response": { "count": 1, "benchmark": 0.22567009925842, "requests": [ { "request": { ...
13
votes
2answers
22k views

Deserialize JSON to SObject

Following code is giving me common.apex.runtime.impl.ExecutionException String jsonText = '{"Data": {"attributes": {"type": "Contact"},"Id": "0036100000JUXKkAAP","Description": "","LastName": "...
11
votes
1answer
1k views

How to deserialize into interface type when concrete type is unknown

As a follow up to this question: I am essentially trying to deserialize a JSON object into an Interface Type. Unfortunately we cannot deserialize using an Interface as the ApexType and must know ...
10
votes
2answers
1k views

Unfamiliar Syntax

I came across the following code online: @future(callout=true) public static void runWarehouseEquipmentSync(){ Http http = new Http(); HttpRequest request = new HttpRequest(); request....
10
votes
1answer
7k views

Why is String.valueOf(Blob) different that Blob.toString()?

I am working on a REST Service that will desiralize the request body and interpret it. My understanding was that calling String.valueOf(objectInstance) would just call objectInstance.toString(). ...
9
votes
4answers
32k views

how to parse the JSON object in salesforce

how to parse the json string . here multiple contact,multiple postalcode and mulitple contactnumber .how can i get the values from this json output.like list of contacts,list of postalcode and list of ...
9
votes
2answers
586 views

How to Deserialize AggregateResults?

Is it possible to deserialize AggregateResults? If not, why? When I try it the regular way, all my aggregate results are empty: List<AggregateResult> arList = [SELECT Name FROM Account GROUP BY ...
9
votes
1answer
2k views

APEX ENUM Serialize to and Deserialize from JSON

I have APEX classes defined with enum properties that are to be serialized into JSON. Also, I am reading in JSON and deserializing them back to my defined classes. To make the enum properties work ...
9
votes
1answer
1k views

How to deserialize JSON to a class where the same variable name has different data types?

I am trying to deserialize some JSON to a class using JSON.deserialize. My JSON looks like this { "type": "GeometryCollection", "geometries": [ { "type": "Point", ...
7
votes
1answer
2k views

deserializeStrict method: bug?

The documentation about the deserializeStrict method in JSON class is (emphasis added): All attributes in the JSON string must be present in the specified type. If the JSON content contains ...
7
votes
1answer
752 views

Deserialize hits memory limit

We have a custom apex webservice in which we do certain operations and later call a managed package apex method that returns a JSON string which we deserialize and send back to the client. For example ...
6
votes
1answer
19k views

How to serialize an object as JSON?

I have an object that's pretty extensive (lots of properties and child relationships). I'd like to serialize it. So I am doing the following: Proposal__c proposal = (Proposal__c) getRecord(); ...
6
votes
1answer
137 views

JSON.deserialize() for User records wont work

I'm trying to deserialize a received user record on a JSON format. TO achieve this I'm using JSON.deserialize() but when I specify the User class the compiler throws the following error: Save Error:...
5
votes
2answers
265 views

Copy the properties from one instance of an Apex Class to another

I am attempting to copy the properties from one Apex class instance to another (without hard coding the property names). See the below example: public class Post{ public String name ...
5
votes
0answers
883 views

JSON parsing to Visualforce page difficulties

Following my previous question here I've been dealing with some pretty crappy JSON for an assessment submission and trying to display it in a VF page as a table, ultimately with questions, available ...
4
votes
1answer
1k views

JSON.deserializeUntyped returns “unrecognized token: 'NULL'”, when JSON token has a null value

We're creating our JSON responses to my salesforce callouts in house, so I'm guessing the issue has to do with how we're representing NULL in the JSON response. Here's a snippet of the response SF ...
4
votes
1answer
1k views

JSON Serialize and Deserialize on HttpRequest

In order to make a @future(callout=true) call, I'm serializing an HTTPRequest object in order to send it to the @future method accepting a String jsonHttpRequest parameter. Instance Method ...
4
votes
2answers
4k views

How to parse XML data to JSON? How to deserialize XML to Apex class?

I Have Xml data as Follows String Data_XML = '<?xml version="1.0" encoding=""?> <book><price>100</price><Items>2</Items> </book>'; I wanted to deserialize ...
4
votes
1answer
523 views

Deserializing a list of jsons

I am trying to deserialize a list of jsons. If I have only one json like so '{"apple":"green"}' I can parse it using JSON.deserializeUntyped: Map<String, Object> input = (Map<String, ...
4
votes
1answer
205 views

Cannot use deserialized JSON for populating map - why?

I have deserialized some JSON into lists of objects: Map<String, Object> Results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody()); List<Object> ...
4
votes
2answers
290 views

How to adding dynamic rows/fields to wrapper class?

I have written the following WrapperClass, consisting different object records/rows/fields as members. How can I dynamically update this wrapper class object. In below code i have used only two fields ...
4
votes
3answers
272 views

Deserialising a DateString

I do: Date d = (Date)JSON.deserialize('2013-06-07T00:00:00.000Z', Date.class); System.debug('**********d = ' + d); I expect: *************d = 2013-06-07 00:00:00 I see: *************d = 2013-01-...
3
votes
2answers
471 views

Is it possible to JSON.deserializeUntyped directly to DateTime without information about field is DateTime?

I wonder if it is possible to JSON.deserializeUntyped directly to DateTime type. How can I check if deserialized Object in Map has type of DateTime? I am curious is it possible, because Object in ...
3
votes
2answers
3k views

System.TypeException: Invalid conversion from runtime type Map<String,ANY> to Map<String,String>

I have the following Program which gives me the following error: System.TypeException: Invalid conversion from runtime type Map<String,ANY> to Map<String,String> The program which I ...
3
votes
2answers
4k views

Deserializing an Account throws an error

I have this very simple example that serializes and deserializes the first Account found: System.debug((Account) JSON.deserialize( JSON.serialize([SELECT Id, Name FROM Account LIMIT 1]), ...
3
votes
2answers
2k views

Process JSON Array

Can someone tell me how to process JSON Array in an Apex REST resource class ?. My input to the HTTP post method will be like as follows. [ { "Name":"1 A" }, { "Name":"1 B"...
3
votes
1answer
2k views

Parse dynamic JSON with Apex

I am receiving the following JSON as a result of a web callout: { "count" : 1, "posts" : { "1234567" : { "id" : "1234567", "private" : false, "message" : "...
3
votes
1answer
699 views

Having trouble deserializing a JSON object that contains SF Ids

I am using an geocoding API called Geocodio to process a batch of addresses. I felt I had a good handle on deserializing JSON arrays, but am having trouble deserializing a response that doesn't have ...
3
votes
1answer
643 views

How to parse YAML object in Salesforce Apex

I get a YAML string from REST service response in Apex code and I look for some similar way how to parse it and convert to collection of Salesforce objects. For instance, I get such YAML as string: ...
3
votes
1answer
4k views

JSON deserialize into wrapper class errors

I'm trying to set up integration to display quiz answers in a Visualforce page, but I'm having a lot of difficulty deserializing a JSON string (supplied via API call response) into a wrapper class ...
3
votes
2answers
376 views

PHP Toolkit 20.0 (Enterprise) Upsert/Update Custom Object - deserializer not found

I'm using PHP Toolkit 20.0 (Enterprise) and the latest WSDL. Partner also fails for me. I can successfully create (using PHP Toolkit create) objects of this type. All my attempts to Update or Upsert ...
3
votes
0answers
758 views

How to access deserialized nested SObjects

I am implementing a custom REST API to support upserting a related set of records, similar to the Salesforce composite REST API. Main reason for that is because I want all DML operations to be part of ...
2
votes
1answer
692 views

Json Deserialization

EDIT 2: Apparently Apex has no idea what escaping character is... after I removed manually all '\' from that JSON, it worked. I know this question was asked tens of times, but so far nothing works ...
2
votes
1answer
190 views

deserialising JSON best practice/efficiently

I have the following JSON structure { "PLU":{ "high":"N/A", "low":"N/A", "percentChange":"0", "baseVolume":"0", "quoteVolume":"0" }, "1ST":{ "high":"0.00033386", "low":"0.00033386"...
2
votes
1answer
2k views

SOAP callout error: Failed to deserialize value

I am testing an integration between Salesforce and another system via Web Service Collouts. For that, I am using WSDL->APEX generated class. When invoke the web service via anonymous apex, I get a ...
2
votes
1answer
649 views

How to do a DML upsert/insert loop in custom object after JSON deserialization?

I'm fairly new to Apex and I am completely at a loss at what to do next. So far I was able to grab and deserialize my JSON I grabbed from a Web Service(This does a GET Method for info for salespeople)....
2
votes
1answer
679 views

APEX Deserializing/Parsing RESTful JSON Webservice Response

I'm trying to get JSON data from a RESTful webservice into SFDC. My attempts have failed as I keep getting the following error: System.JSONException: Malformed JSON: Expected '{' at the beginning ...
2
votes
2answers
3k views

What XML support salesforce provides in apex

(i) Is it possible to directly serialize/deserialize sObject record to xml in apex code? (ii) Is it possible to serialize/deserialize apex object to/from xml?
2
votes
1answer
183 views

How to advoid Unknown field: MyJSON.number

I am having trouble with deserialising a jsonstring. In my debug I get the error System.JSONException: Unknown field: MyJSON.number. As number is a reserved field in salesforce I replace it with ...
2
votes
1answer
822 views

JSON.deserialize on custom sObject not parsing related fields from lookup relationship

I've got a map whose values are a wrapper class. The wrapper class holds a custom sObject list, and the sObject in turn was queried to include related fields from a lookup relationship. Problem is, ...
2
votes
1answer
3k views

JSON deserialize a list of a list

I'm trying to deserialize the following JSON which I'm obtaning from the Google Cloud Platform Translation API: { "data": { "detections": [ [ { ...
2
votes
1answer
1k views

How to serialize the JSON response?

i'm trying to convert the json response as sObject(Case). but i'm little confusion to map external sys fields with sobject fields this is my JSON response : {"result":[{"short_description":"Can'...
2
votes
1answer
2k views

Changing property names when serializing JSON [duplicate]

Is there any way to set the name of the serializable field? I'm trying to work with JIRA webhooks and I ran into an issue where their request package contains a field that is a protected keyword in ...
2
votes
1answer
2k views

Handling hyphens in JSON deserialization

I am trying to use public REST API that that has hyphens in variable names. Apex does not support variable names with hyphens. JSON2Apex tool generates kind of strange class as well. I was facing ...
2
votes
1answer
666 views

Calling JSON.deserialize() throws “System.NullPointerException: Attempt to de-reference a null object”

I'm trying to use the System method JSON.deserialize(jsonString, apexType) to deserialize the body of an ApexRest POST request. My code compiles, but at runtime I'm getting a System....
2
votes
1answer
2k views

deserializing JSON returns a null object

I'm trying to deserialize a JSON response into a list, so that eventually I can iterate through the list and create new contacts from the response. This is my first time working with APIs and JSON, ...
2
votes
2answers
1k views

Trailhead Apex Super Badge JSON Parsing

Working on the Trailhead Apex Super Badge.... There is a section that requires writing a rest callout that returns a chunk of JSON that you are to use to update Product2 records with. Reduced Chunk ...
2
votes
1answer
8k views

Access sObject list variables in Javascript

Question: I need to create list of sObjects in Javascript. Let's assume accountWrapperList is a list of (Account + checkbox) defined in controller. You can access this list in your javascript if you ...
2
votes
1answer
9k views

Apex: Get value from first element of Map

I am receiving the following JSON for a web service: { "count" : 1, "posts" : { "1234567" : { "id" : "1234567", "private" : false, "message" : "New post on Monday Jan 5th", ...