Salesforce Apex JSON serialization with change on variable name

0 votes
In Salesforce/Apex how can i serialize an Apex Class to Json/String with a change of variable names mapping ? like in java we can use @SerializedName annotation.
Mar 2, 2022 in SalesForce by surbhi
• 3,810 points
3,752 views

1 answer to this question.

0 votes
Apex does not support annotation for serialization.

But, in this type of scenario, I always follows

public class TestClass
{
    public string oldA { get; set; }
    public string oldB { get; set; }
    public string oldC { get; set; }
}

String jsonStr = JSON.serialize(objectTestClass);
jsonStr = jsonStr.replaceAll('"oldA":','"newA":');
You can use JSONGenerator to create the output yourself
answered Mar 2, 2022 by surbhi
• 3,810 points

Related Questions In SalesForce

0 votes
1 answer

Apex (Salesforce) read json from response and store it in a string variable

String jsonStr = '{ "oktaToken":"eyJraWQiOiIyNlN1NHFMNnVVZTVJX2M5X2Z3WmZvX09ON0dNUHRtQzlEeHFsTGplLS00IiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULlVINmdIOF9BcWJ" }'; Map<String, String> ...READ MORE

answered Mar 3, 2022 in SalesForce by CoolCoder
• 4,400 points

edited Jun 27, 2023 by Khan Sarfaraz 9,380 views
0 votes
0 answers

Apex (Salesforce) read json from response and store it in a string variable

I am trying to hit a API ...READ MORE

Mar 4, 2022 in SalesForce by surbhi
• 3,810 points
1,140 views
0 votes
0 answers

Salesforce Apex SingleEmailMessage with Template to User not contact

Im trying to send an email in ...READ MORE

Feb 28, 2022 in SalesForce by surbhi
• 3,810 points
2,919 views
0 votes
1 answer

Salesforce Apex SingleEmailMessage with Template to User not contact

// Pick a dummy Contact Contact c ...READ MORE

answered Mar 17, 2022 in SalesForce by CoolCoder
• 4,400 points

edited Jun 27, 2023 by Khan Sarfaraz 4,242 views
+2 votes
2 answers

Salesforce Interview questions

Here are some questions very important for ...READ MORE

answered Jan 11, 2019 in Career Counselling by Suresh
• 720 points
3,057 views
0 votes
1 answer

How to connect to salesforce from tableau?

Hi, follow these steps to connect to Salesforce: 1. ...READ MORE

answered Mar 25, 2019 in Tableau by Cherukuri
• 33,030 points
850 views
0 votes
1 answer

Power BI - Salesforce

Hi, Follow below steps: 1. Go to Data source. 2. ...READ MORE

answered Mar 25, 2019 in Power BI by Cherukuri
• 33,030 points
544 views
0 votes
2 answers

What is the best training for Salesforce ADM-201 Exam?

Hi @Vardhan, I took Edureka's Salesforce Online Training, ...READ MORE

answered Jun 3, 2021 in Others by Jaya
• 140 points

edited Dec 22, 2021 by Soumya 621 views
0 votes
1 answer

Json response to be deserialized in Apex salesforce lightning

Because some fields in Apex Salesforce are ...READ MORE

answered Mar 2, 2022 in SalesForce by surbhi
• 3,810 points
3,404 views
0 votes
1 answer

Username/password JWT with Salesforce Named Credentials

Although Named Credentials cannot be used to ...READ MORE

answered Mar 2, 2022 in SalesForce by surbhi
• 3,810 points
1,957 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP