You need to sign in to do that
Don't have an account?
RestResource REST API returns different results for XML vs JSON
@RestResource(urlMapping='/api/restqa') global with sharing class Jay_RestTest { global virtual class BaseDemo { public String className { set; get; } } global class Demo extends BaseDemo { public String Name { set; get; } } @HttpGet global static BaseDemo doGet() { Demo d = new Demo(); d.className = 'Demo'; d.Name = 'Jay'; return d; } }
In the above code if the Accept type is application/json I will get
{ "className": "Demo", "Name": "Jay" }
But if its application/xml then I get
<?xml version="1.0" encoding="UTF-8"?> <response xmlns:Demo="http://soap.sforce.com/schemas/class/Jay_RestTest"> <Demo:Name>Jay</Demo:Name> </response>
As you can see the value of the base class is missing
Jay
Please do below changes in your Apex Class and try
Execute with below Contect Type
Content-Type: application/xml; charset=UTF-8
Accept: application/xml
Response will be :- Execute with below Contect Type
Content-Type: application/json; charset=UTF-8
Accept: application/json
Response will be :-
NOTE:- If you will not genrate the response then salesforce is using there own parser which is creating the wrapper of return type class only.
Please check below respone . Salesforce is also adding the class name
<Demo:className>Demo</Demo:className>
<Demo:Name>Jay</Demo:Name>
Please let us know if this will help you.