Update: apparently this is only an issue with a concrete type on my own class. Tried the same code with the Contact
sObject, no exception thrown.
Controller
public with sharing class DateTimeSerializationController {
public class MyItem {
public String name { get; set; }
public DateTime theDate { get; set; }
}
@RemoteAction
public static MyItem fetchTheItem() {
MyItem item = new MyItem();
item.name = 'Item Name';
item.theDate = DateTime.now();
return item;
}
@RemoteAction
public static MyItem storeTheItem(MyItem item) {
// DML or something similar could happen here
system.debug(item);
return item;
}
@RemoteAction
public static Contact fetchTheContact() {
Contact item = new Contact();
item.FirstName = 'Joe';
item.LastName = 'Bob';
item.My_Date__c = DateTime.now();
return item;
}
@RemoteAction
public static Contact storeTheContact(Contact item) {
// DML or something similar could happen here
system.debug(item);
return item;
}
}
<apex:page controller="DateTimeSerializationController">
<script>
window.myApp = window.myApp || {};
window.myApp.fetchfetchItem = function() {
Visualforce.remoting.Manager.invokeAction(
'DateTimeSerializationController.fetchTheItem',
function(result, event){
if (event.status) {
console.log(result);
myApp.myItem = result;
} else {
console.log(event.message);
}
},
{escape: true}
);
}
window.myApp.storestoreItem = function() {
Visualforce.remoting.Manager.invokeAction(
'DateTimeSerializationController.storeTheItem',
myApp.myItem,
function(result, event){
if (event.status) {
console.log(result);
} else {
console.log(event.message);
}
},
{escape: true}
);
}
window.myApp.fetchContact = function() {
Visualforce.remoting.Manager.invokeAction(
'DateTimeSerializationController.fetchTheContact',
function(result, event){
if (event.status) {
console.log(result);
myApp.myContact = result;
} else {
console.log(event.message);
}
},
{escape: true}
);
}
window.myApp.storeContact = function() {
Visualforce.remoting.Manager.invokeAction(
'DateTimeSerializationController.storeTheContact',
myApp.myContact,
function(result, event){
if (event.status) {
console.log(result);
} else {
console.log(event.message);
}
},
{escape: true}
);
}
</script>
<p>Open the browser console and then click the buttons.</p>
<button onclick="myApp.fetchItem();">Fetch Item</button>
<button onclick="myApp.fetchstoreItem();">Fetch<;">Store Item</button>
<button onclick="myApp.storefetchContact();">Store<;">Fetch Contact</button>
<button onclick="myApp.storeContact();">Store Contact</button>
</apex:page>