I'm trying to parse a Time field from my lightning component to my apex controller by using JSON and deserializing it in apex into an existing Object.
But unfortunately I'm always getting the error
Cannot deserialize instance of time from VALUE_STRING value 10:30:00.000Z
I already tried different Time formats and with/without quotes "" in my JSON
- 10:30
- 10:30:00
- 10:30:00.000
- 10:30:00.000Z
- T10:00:00.000Z
- 2018-06-07T10:00:00.000Z
But nothing works.
- My Org is on Spring 18 API Version 42
- I have an SObject (Event__c) with a Time Field
The problem is reproducable in anonymous apex with following code
Event__c workingObject = new Event__c();
workingObject.Name = 'Lorem';
workingObject.Public_Start_Time__c = Time.newInstance(10,10,10,10);
String serializedObject = JSON.serialize(workingObject);
String mixedObject = '{"Public_Start_Time__c": "' + workingObject.Public_Start_Time__c + '", "name": "Ipsum"}';
String manualObject = '{"Public_Start_Time__c": "2018-06-07T10:00:00.000Z", "name": "Dolor"}';
try {
Event__c banana = (Event__c)JSON.deserialize(serializedObject, Event__c.class);
}
catch(Exception ex) {
System.debug(ex.getMessage());
}
try {
Event__c banana = (Event__c)JSON.deserialize(mixedObject, Event__c.class);
}
catch(Exception ex) {
System.debug(ex.getMessage());
}
try {
Event__c banana = (Event__c)JSON.deserialize(manualObject, Event__c.class);
}
catch(Exception ex) {
System.debug(ex.getMessage());
}
which results in the 3 following messages
Cannot deserialize instance of time from VALUE_STRING value 10:10:10.010Z or request may be missing a required field
Cannot deserialize instance of time from VALUE_STRING value 10:10:10.010Z or request may be missing a required field
Cannot deserialize instance of time from VALUE_STRING value 2018-06-07T10:00:00.000Z or request may be missing a required field
Everything I found so far was for dates or datetimes but not time only.