You need to sign in to do that
Don't have an account?
Quddus Ololade 4
Unable to get the deserialized object to lightning controller
Component:
In apex debug log, I see that the JSON object has been successfully parsed, while in a lightning controller, I don't get the value in response.getreturnvalue() for this apex method (JsonGetValue) also nothing in the console.log
I saw in a couple of blogs that we can pass an object from APEX and refer it in lightning controller and component
Can someone help me understand why I am not getting the object in the lightning controller console log
<aura:component controller="LightningController" implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global" > <aura:attribute name="purposes" type="ApexDataContainer" /> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> data: {!v.purposes} </aura:component>Controller
({ doInit : function(component, event, helper) { var getdata = component.get("c.JsonGetValue"); getdata.setCallback(this, function(response){ var state = response.getState(); if (state === 'SUCCESS'){ var result = response.getReturnValue(); console.log('1'+JSON.stringify(result)); console.log('2'+result['purposes']); component.set("v.purposes",response.getReturnValue()); } }); $A.enqueueAction(getdata); } })Apex:
public class LightningController { @AuraEnabled public static ApexDataContainer JsonGetValue() { ApexDataContainer c1 = new ApexDataContainer(); System.debug('hello'); String json1= '{'+ ''+ ' "purposes": ['+ ''+ ' {'+ ''+ ' "purpose": "service-improvement",'+ ''+ ' "legalGround": "ic",'+ ''+ ' "status": "not_answered",'+ ''+ ' "description": ['+ ''+ ' {'+ ''+ ' "language": "sv-EN",'+ ''+ ' "text": "Service data structure"'+ ''+ ' }'+ ''+ ' ],'+ ''+ ' "version": "1.0.0",'+ ''+ ' "dataIds": []'+ ''+ ' }'+ ' ]'+ ''+ '}'; c1 = (ApexDataContainer)JSON.deserialize(json1,ApexDataContainer.class); system.debug('wrapper'+c1.purposes.size()); return c1; } }
In apex debug log, I see that the JSON object has been successfully parsed, while in a lightning controller, I don't get the value in response.getreturnvalue() for this apex method (JsonGetValue) also nothing in the console.log
I saw in a couple of blogs that we can pass an object from APEX and refer it in lightning controller and component
Can someone help me understand why I am not getting the object in the lightning controller console log
But I am getting an issue in parsing only when I send the request using REST API
I have seen in the debug log before making a call out that we have the valid json but once it hits the service I get the response as
With the same json string if I do within classes, it gets successfully parsed, do we need to do anything extra in REST call out while sending Json request as string.
The ApexDataContainer class is exactly same in both the environments. The request gets failed in the method invoke.
Any ideas here