I am having trouble passing an apex wrapper class from LWC into APEX.
Apex
@AuraEnabled
public static void myMethod(SomeData theData) {
system.debug('theData is ' + theData);
}
public class SomeData {
public String theString;
public Object theObject;
}
LWC
connectedCallback() {
const myData= {
'theString': 'Test',
'theObject': true
};
myMethod({theData: myData})
.then(result => {
if (result) {
}
} catch(err) {
}
}
When I run the code above what I get from APEX is [theString=null, theObject=null]
.
However if I modify the signature of the APEX method to be public static void myMethod(String theString, Object theObject) {
and respectively pass that from the JS side myMethod({theString: myString, theObject: myObject})
where myString = 'Test';
and myObject = true
that gets parsed properly in APEX and I can see it in the debugs.
I also tried specifying the sobjectType
when instantiating the JS object like but that didn't help either:
const myData= {
'sobjectType': 'SomeData',
'theString': 'Test',
'theObject': true
};