JSON.serialize Question - Slack integrationJSON.Serialize method not returning null fieldsBug? Why doesn't...
Simple interepretation problem regarding Polynomial Hierarchy?
Why were Er and Onan punished if they were under 20?
Are randomly-generated passwords starting with "a" less secure?
How to wire 3 hots / 3 neutrals into this new TR outlet with 2 screws?
Reverse dots and boxes, swastika edition
How can a dictatorship government be beneficial to a dictator in a post-scarcity society?
Terry Pratchett book with a lawyer dragon and sheep
Why are all my yellow 2V/20mA LEDs burning out with 330k Ohm resistor?
Why isn't there research to build a standard lunar, or Martian mobility platform?
C program to parse source code of another language
JSON.serialize Question - Slack integration
Managing and organizing the massively increased number of classes after switching to SOLID?
Using Newton's shell theorem to accelerate a spaceship
Print the last, middle and first character of your code
How would vampires avoid contracting diseases?
Why isn't pressure filtration popular compared to vacuum filtration?
How can one write good dialogue in a story without sounding wooden?
Why was hardware diversification an asset for the IBM PC ecosystem?
Misspelling my name on my mathematical publications
Why weren't bootable game disks ever common on the IBM PC?
Is a request to book a business flight ticket for a graduate student an unreasonable one?
What steps should I take to lawfully visit the United States as a tourist immediately after visiting on a B-1 visa?
Why do players in the past play much longer tournaments than today's top players?
Is anyone advocating the promotion of homosexuality in UK schools?
JSON.serialize Question - Slack integration
JSON.Serialize method not returning null fieldsBug? Why doesn't JSON.serialize support DescribeSObjectResult?Checkmarx and JSON.serializeProcessing a json api response using JSONParser classSlack Salesforce Integration with Web Hooks creating snippetHow to JSON.serialize not including null valuesjson.serialize returning nullIntegration QuestionJSON.serialize Url object throwing System.JSONExceptionHas JSON.serialize suppressApexObjectNulls ever worked?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I am looking to create a slack payload. I am struggling to create this payload in Apex.
{
"username": "Bot Name",
"text": "*Call Recording* :tada:",
"attachments":[
{
"author_name": "Dean",
"title": "Call Recording",
"title_link": "https://api.slack.com/",
"color": "#36a64f",
"fields": [
{
"title": "Account",
"value": "var",
"short": true
},
{
"title": "Contact",
"value": "var",
"short": true
}
]
}
],
"icon_emoji": ":dromedary_camel:"
}
So far I have created the following:
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject(); //Inserts {
gen.writeStringField('channel', r.channel);
gen.writeStringField('icon_emoji', ':dromedary_camel:');
gen.writeStringField('username', r.bot_username_var);
gen.writeStringField('text', r.title_var);
gen.writeFieldName('attachments');
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('author_name', r.rep_var);
gen.writeStringField('title', r.call_recording_title_var);
gen.writeStringField('title_link', r.call_recording_title_var);
gen.writeStringField('color', '#36a64f');
gen.writeFieldName('fields');
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('title', 'Account');
gen.writeStringField('value', r.account_var);
gen.writeStringField('short', true);
gen.writeEndObject();
gen.writeStartObject();
gen.writeStringField('title', 'Contact');
gen.writeStringField('value', r.contact_var);
gen.writeStringField('short', true);
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject(); //Inserts }
String body = gen.getAsString(); //Translates JSONGenerator to string to be passed to callout
apex json
add a comment |
I am looking to create a slack payload. I am struggling to create this payload in Apex.
{
"username": "Bot Name",
"text": "*Call Recording* :tada:",
"attachments":[
{
"author_name": "Dean",
"title": "Call Recording",
"title_link": "https://api.slack.com/",
"color": "#36a64f",
"fields": [
{
"title": "Account",
"value": "var",
"short": true
},
{
"title": "Contact",
"value": "var",
"short": true
}
]
}
],
"icon_emoji": ":dromedary_camel:"
}
So far I have created the following:
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject(); //Inserts {
gen.writeStringField('channel', r.channel);
gen.writeStringField('icon_emoji', ':dromedary_camel:');
gen.writeStringField('username', r.bot_username_var);
gen.writeStringField('text', r.title_var);
gen.writeFieldName('attachments');
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('author_name', r.rep_var);
gen.writeStringField('title', r.call_recording_title_var);
gen.writeStringField('title_link', r.call_recording_title_var);
gen.writeStringField('color', '#36a64f');
gen.writeFieldName('fields');
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('title', 'Account');
gen.writeStringField('value', r.account_var);
gen.writeStringField('short', true);
gen.writeEndObject();
gen.writeStartObject();
gen.writeStringField('title', 'Contact');
gen.writeStringField('value', r.contact_var);
gen.writeStringField('short', true);
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject(); //Inserts }
String body = gen.getAsString(); //Translates JSONGenerator to string to be passed to callout
apex json
1
This might help -- json2apex.herokuapp.com
– kurunve
9 hours ago
Wow, there has to be an easier way
– Matthew Metros
9 hours ago
4
Don't ever useJSONGenerator
. It is slow, more complicated, and usage of it leads to more complicated or lower value tests.
– Adrian Larson♦
8 hours ago
@AdrianLarson so what would you recommend?
– Matthew Metros
8 hours ago
1
Use the built inJSON.serialize
andJSON.deserialize
methods. Create a class to model your data structure so that you can use that for the target/source of those methods.
– Adrian Larson♦
7 hours ago
add a comment |
I am looking to create a slack payload. I am struggling to create this payload in Apex.
{
"username": "Bot Name",
"text": "*Call Recording* :tada:",
"attachments":[
{
"author_name": "Dean",
"title": "Call Recording",
"title_link": "https://api.slack.com/",
"color": "#36a64f",
"fields": [
{
"title": "Account",
"value": "var",
"short": true
},
{
"title": "Contact",
"value": "var",
"short": true
}
]
}
],
"icon_emoji": ":dromedary_camel:"
}
So far I have created the following:
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject(); //Inserts {
gen.writeStringField('channel', r.channel);
gen.writeStringField('icon_emoji', ':dromedary_camel:');
gen.writeStringField('username', r.bot_username_var);
gen.writeStringField('text', r.title_var);
gen.writeFieldName('attachments');
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('author_name', r.rep_var);
gen.writeStringField('title', r.call_recording_title_var);
gen.writeStringField('title_link', r.call_recording_title_var);
gen.writeStringField('color', '#36a64f');
gen.writeFieldName('fields');
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('title', 'Account');
gen.writeStringField('value', r.account_var);
gen.writeStringField('short', true);
gen.writeEndObject();
gen.writeStartObject();
gen.writeStringField('title', 'Contact');
gen.writeStringField('value', r.contact_var);
gen.writeStringField('short', true);
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject(); //Inserts }
String body = gen.getAsString(); //Translates JSONGenerator to string to be passed to callout
apex json
I am looking to create a slack payload. I am struggling to create this payload in Apex.
{
"username": "Bot Name",
"text": "*Call Recording* :tada:",
"attachments":[
{
"author_name": "Dean",
"title": "Call Recording",
"title_link": "https://api.slack.com/",
"color": "#36a64f",
"fields": [
{
"title": "Account",
"value": "var",
"short": true
},
{
"title": "Contact",
"value": "var",
"short": true
}
]
}
],
"icon_emoji": ":dromedary_camel:"
}
So far I have created the following:
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject(); //Inserts {
gen.writeStringField('channel', r.channel);
gen.writeStringField('icon_emoji', ':dromedary_camel:');
gen.writeStringField('username', r.bot_username_var);
gen.writeStringField('text', r.title_var);
gen.writeFieldName('attachments');
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('author_name', r.rep_var);
gen.writeStringField('title', r.call_recording_title_var);
gen.writeStringField('title_link', r.call_recording_title_var);
gen.writeStringField('color', '#36a64f');
gen.writeFieldName('fields');
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('title', 'Account');
gen.writeStringField('value', r.account_var);
gen.writeStringField('short', true);
gen.writeEndObject();
gen.writeStartObject();
gen.writeStringField('title', 'Contact');
gen.writeStringField('value', r.contact_var);
gen.writeStringField('short', true);
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject(); //Inserts }
String body = gen.getAsString(); //Translates JSONGenerator to string to be passed to callout
apex json
apex json
edited 7 hours ago
cropredy
38.1k4 gold badges45 silver badges132 bronze badges
38.1k4 gold badges45 silver badges132 bronze badges
asked 9 hours ago
Matthew MetrosMatthew Metros
1327 bronze badges
1327 bronze badges
1
This might help -- json2apex.herokuapp.com
– kurunve
9 hours ago
Wow, there has to be an easier way
– Matthew Metros
9 hours ago
4
Don't ever useJSONGenerator
. It is slow, more complicated, and usage of it leads to more complicated or lower value tests.
– Adrian Larson♦
8 hours ago
@AdrianLarson so what would you recommend?
– Matthew Metros
8 hours ago
1
Use the built inJSON.serialize
andJSON.deserialize
methods. Create a class to model your data structure so that you can use that for the target/source of those methods.
– Adrian Larson♦
7 hours ago
add a comment |
1
This might help -- json2apex.herokuapp.com
– kurunve
9 hours ago
Wow, there has to be an easier way
– Matthew Metros
9 hours ago
4
Don't ever useJSONGenerator
. It is slow, more complicated, and usage of it leads to more complicated or lower value tests.
– Adrian Larson♦
8 hours ago
@AdrianLarson so what would you recommend?
– Matthew Metros
8 hours ago
1
Use the built inJSON.serialize
andJSON.deserialize
methods. Create a class to model your data structure so that you can use that for the target/source of those methods.
– Adrian Larson♦
7 hours ago
1
1
This might help -- json2apex.herokuapp.com
– kurunve
9 hours ago
This might help -- json2apex.herokuapp.com
– kurunve
9 hours ago
Wow, there has to be an easier way
– Matthew Metros
9 hours ago
Wow, there has to be an easier way
– Matthew Metros
9 hours ago
4
4
Don't ever use
JSONGenerator
. It is slow, more complicated, and usage of it leads to more complicated or lower value tests.– Adrian Larson♦
8 hours ago
Don't ever use
JSONGenerator
. It is slow, more complicated, and usage of it leads to more complicated or lower value tests.– Adrian Larson♦
8 hours ago
@AdrianLarson so what would you recommend?
– Matthew Metros
8 hours ago
@AdrianLarson so what would you recommend?
– Matthew Metros
8 hours ago
1
1
Use the built in
JSON.serialize
and JSON.deserialize
methods. Create a class to model your data structure so that you can use that for the target/source of those methods.– Adrian Larson♦
7 hours ago
Use the built in
JSON.serialize
and JSON.deserialize
methods. Create a class to model your data structure so that you can use that for the target/source of those methods.– Adrian Larson♦
7 hours ago
add a comment |
1 Answer
1
active
oldest
votes
The simplest way for you to do this is to leverage a custom class, like so:
Classes (you can put them all inside of a larger class, or keep them as individual Apex Classes
public class mySlackPayload {
public String username;
public String text;
public List<mySlackAttachment> attachments;
<the rest of your props go here>
}
public class mySlackAttachment {
<attachment props go here>
}
Then, in your current code, you can do this
mySlackPayload myPayload = new mySlackPayload();
myPayload.username = 'xxx';
<fill the rest of the props>
String serializedPayload = JSON.serialize(myPayload);
Doing this with sObjects will add extraneous properties added by Apex that will mess up that payload un-necessarily. You can also add constructors to those classes to take an sObject as a parameter and populate properties accordingly.
PS: The tool described in comments by @kurunve should generate this custom class for you (I admit I find the result of that class a bit bloated), then you would simply use the second part of my code to populate and call it.
Should I look into the JSONGenerator class? JSONGenerator gen = JSON.createGenerator(true);
– Matthew Metros
8 hours ago
1
I don't think it makes sense. When you serialize a class it'll come out neat as you specified in your original post. But you have to build that class first to mimic the JSON output you want
– Sebastian Kessel
8 hours ago
why are you doing JSON.serialize(mySlackPayload) I thought you would do JSON.serialize(myPayload)
– Matthew Metros
8 hours ago
1
Oh, that is correct, and a typo. Fixing that.
– Sebastian Kessel
8 hours ago
1
@MatthewMetros - seconding Sebastian's solution as that is what I did for my Slack integration with one exception - I added atoJson()
method onMySlackPayload
class to make it a bit more OO
– cropredy
7 hours ago
|
show 3 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f268961%2fjson-serialize-question-slack-integration%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
The simplest way for you to do this is to leverage a custom class, like so:
Classes (you can put them all inside of a larger class, or keep them as individual Apex Classes
public class mySlackPayload {
public String username;
public String text;
public List<mySlackAttachment> attachments;
<the rest of your props go here>
}
public class mySlackAttachment {
<attachment props go here>
}
Then, in your current code, you can do this
mySlackPayload myPayload = new mySlackPayload();
myPayload.username = 'xxx';
<fill the rest of the props>
String serializedPayload = JSON.serialize(myPayload);
Doing this with sObjects will add extraneous properties added by Apex that will mess up that payload un-necessarily. You can also add constructors to those classes to take an sObject as a parameter and populate properties accordingly.
PS: The tool described in comments by @kurunve should generate this custom class for you (I admit I find the result of that class a bit bloated), then you would simply use the second part of my code to populate and call it.
Should I look into the JSONGenerator class? JSONGenerator gen = JSON.createGenerator(true);
– Matthew Metros
8 hours ago
1
I don't think it makes sense. When you serialize a class it'll come out neat as you specified in your original post. But you have to build that class first to mimic the JSON output you want
– Sebastian Kessel
8 hours ago
why are you doing JSON.serialize(mySlackPayload) I thought you would do JSON.serialize(myPayload)
– Matthew Metros
8 hours ago
1
Oh, that is correct, and a typo. Fixing that.
– Sebastian Kessel
8 hours ago
1
@MatthewMetros - seconding Sebastian's solution as that is what I did for my Slack integration with one exception - I added atoJson()
method onMySlackPayload
class to make it a bit more OO
– cropredy
7 hours ago
|
show 3 more comments
The simplest way for you to do this is to leverage a custom class, like so:
Classes (you can put them all inside of a larger class, or keep them as individual Apex Classes
public class mySlackPayload {
public String username;
public String text;
public List<mySlackAttachment> attachments;
<the rest of your props go here>
}
public class mySlackAttachment {
<attachment props go here>
}
Then, in your current code, you can do this
mySlackPayload myPayload = new mySlackPayload();
myPayload.username = 'xxx';
<fill the rest of the props>
String serializedPayload = JSON.serialize(myPayload);
Doing this with sObjects will add extraneous properties added by Apex that will mess up that payload un-necessarily. You can also add constructors to those classes to take an sObject as a parameter and populate properties accordingly.
PS: The tool described in comments by @kurunve should generate this custom class for you (I admit I find the result of that class a bit bloated), then you would simply use the second part of my code to populate and call it.
Should I look into the JSONGenerator class? JSONGenerator gen = JSON.createGenerator(true);
– Matthew Metros
8 hours ago
1
I don't think it makes sense. When you serialize a class it'll come out neat as you specified in your original post. But you have to build that class first to mimic the JSON output you want
– Sebastian Kessel
8 hours ago
why are you doing JSON.serialize(mySlackPayload) I thought you would do JSON.serialize(myPayload)
– Matthew Metros
8 hours ago
1
Oh, that is correct, and a typo. Fixing that.
– Sebastian Kessel
8 hours ago
1
@MatthewMetros - seconding Sebastian's solution as that is what I did for my Slack integration with one exception - I added atoJson()
method onMySlackPayload
class to make it a bit more OO
– cropredy
7 hours ago
|
show 3 more comments
The simplest way for you to do this is to leverage a custom class, like so:
Classes (you can put them all inside of a larger class, or keep them as individual Apex Classes
public class mySlackPayload {
public String username;
public String text;
public List<mySlackAttachment> attachments;
<the rest of your props go here>
}
public class mySlackAttachment {
<attachment props go here>
}
Then, in your current code, you can do this
mySlackPayload myPayload = new mySlackPayload();
myPayload.username = 'xxx';
<fill the rest of the props>
String serializedPayload = JSON.serialize(myPayload);
Doing this with sObjects will add extraneous properties added by Apex that will mess up that payload un-necessarily. You can also add constructors to those classes to take an sObject as a parameter and populate properties accordingly.
PS: The tool described in comments by @kurunve should generate this custom class for you (I admit I find the result of that class a bit bloated), then you would simply use the second part of my code to populate and call it.
The simplest way for you to do this is to leverage a custom class, like so:
Classes (you can put them all inside of a larger class, or keep them as individual Apex Classes
public class mySlackPayload {
public String username;
public String text;
public List<mySlackAttachment> attachments;
<the rest of your props go here>
}
public class mySlackAttachment {
<attachment props go here>
}
Then, in your current code, you can do this
mySlackPayload myPayload = new mySlackPayload();
myPayload.username = 'xxx';
<fill the rest of the props>
String serializedPayload = JSON.serialize(myPayload);
Doing this with sObjects will add extraneous properties added by Apex that will mess up that payload un-necessarily. You can also add constructors to those classes to take an sObject as a parameter and populate properties accordingly.
PS: The tool described in comments by @kurunve should generate this custom class for you (I admit I find the result of that class a bit bloated), then you would simply use the second part of my code to populate and call it.
edited 8 hours ago
answered 8 hours ago
Sebastian KesselSebastian Kessel
9,8316 gold badges23 silver badges39 bronze badges
9,8316 gold badges23 silver badges39 bronze badges
Should I look into the JSONGenerator class? JSONGenerator gen = JSON.createGenerator(true);
– Matthew Metros
8 hours ago
1
I don't think it makes sense. When you serialize a class it'll come out neat as you specified in your original post. But you have to build that class first to mimic the JSON output you want
– Sebastian Kessel
8 hours ago
why are you doing JSON.serialize(mySlackPayload) I thought you would do JSON.serialize(myPayload)
– Matthew Metros
8 hours ago
1
Oh, that is correct, and a typo. Fixing that.
– Sebastian Kessel
8 hours ago
1
@MatthewMetros - seconding Sebastian's solution as that is what I did for my Slack integration with one exception - I added atoJson()
method onMySlackPayload
class to make it a bit more OO
– cropredy
7 hours ago
|
show 3 more comments
Should I look into the JSONGenerator class? JSONGenerator gen = JSON.createGenerator(true);
– Matthew Metros
8 hours ago
1
I don't think it makes sense. When you serialize a class it'll come out neat as you specified in your original post. But you have to build that class first to mimic the JSON output you want
– Sebastian Kessel
8 hours ago
why are you doing JSON.serialize(mySlackPayload) I thought you would do JSON.serialize(myPayload)
– Matthew Metros
8 hours ago
1
Oh, that is correct, and a typo. Fixing that.
– Sebastian Kessel
8 hours ago
1
@MatthewMetros - seconding Sebastian's solution as that is what I did for my Slack integration with one exception - I added atoJson()
method onMySlackPayload
class to make it a bit more OO
– cropredy
7 hours ago
Should I look into the JSONGenerator class? JSONGenerator gen = JSON.createGenerator(true);
– Matthew Metros
8 hours ago
Should I look into the JSONGenerator class? JSONGenerator gen = JSON.createGenerator(true);
– Matthew Metros
8 hours ago
1
1
I don't think it makes sense. When you serialize a class it'll come out neat as you specified in your original post. But you have to build that class first to mimic the JSON output you want
– Sebastian Kessel
8 hours ago
I don't think it makes sense. When you serialize a class it'll come out neat as you specified in your original post. But you have to build that class first to mimic the JSON output you want
– Sebastian Kessel
8 hours ago
why are you doing JSON.serialize(mySlackPayload) I thought you would do JSON.serialize(myPayload)
– Matthew Metros
8 hours ago
why are you doing JSON.serialize(mySlackPayload) I thought you would do JSON.serialize(myPayload)
– Matthew Metros
8 hours ago
1
1
Oh, that is correct, and a typo. Fixing that.
– Sebastian Kessel
8 hours ago
Oh, that is correct, and a typo. Fixing that.
– Sebastian Kessel
8 hours ago
1
1
@MatthewMetros - seconding Sebastian's solution as that is what I did for my Slack integration with one exception - I added a
toJson()
method on MySlackPayload
class to make it a bit more OO– cropredy
7 hours ago
@MatthewMetros - seconding Sebastian's solution as that is what I did for my Slack integration with one exception - I added a
toJson()
method on MySlackPayload
class to make it a bit more OO– cropredy
7 hours ago
|
show 3 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f268961%2fjson-serialize-question-slack-integration%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
This might help -- json2apex.herokuapp.com
– kurunve
9 hours ago
Wow, there has to be an easier way
– Matthew Metros
9 hours ago
4
Don't ever use
JSONGenerator
. It is slow, more complicated, and usage of it leads to more complicated or lower value tests.– Adrian Larson♦
8 hours ago
@AdrianLarson so what would you recommend?
– Matthew Metros
8 hours ago
1
Use the built in
JSON.serialize
andJSON.deserialize
methods. Create a class to model your data structure so that you can use that for the target/source of those methods.– Adrian Larson♦
7 hours ago