in JSLib/src/odata-json.js [69:127]
var jsonApplyMetadata = function (value, metadata, dateParser, recognizeDates) {
/// <summary>Applies metadata coming from both the payload and the metadata object to the value.</summary>
/// <param name="value" type="Object">Data on which the metada is going to be applied.</param>
/// <param name="metadata">Metadata store; one of edmx, schema, or an array of any of them.</param>
/// <param name="dateParser" type="function">Function used for parsing datetime values.</param>
/// <param name="recognizeDates" type="Boolean">
/// True if strings formatted as datetime values should be treated as datetime values. False otherwise.
/// </param>
/// <returns type="Object">Transformed data.</returns>
if (value && typeof value === "object") {
var dataTypeName;
var valueMetadata = value.__metadata;
if (valueMetadata) {
if (valueMetadata.actions) {
valueMetadata.actions = jsonReadAdvertisedActionsOrFunctions(valueMetadata.actions);
}
if (valueMetadata.functions) {
valueMetadata.functions = jsonReadAdvertisedActionsOrFunctions(valueMetadata.functions);
}
dataTypeName = valueMetadata && valueMetadata.type;
}
var dataType = lookupEntityType(dataTypeName, metadata) || lookupComplexType(dataTypeName, metadata);
var propertyValue;
if (dataType) {
var properties = dataType.property;
if (properties) {
var i, len;
for (i = 0, len = properties.length; i < len; i++) {
var property = properties[i];
var propertyName = property.name;
propertyValue = value[propertyName];
if (property.type === "Edm.DateTime" || property.type === "Edm.DateTimeOffset") {
if (propertyValue) {
propertyValue = dateParser(propertyValue);
if (!propertyValue) {
throw { message: "Invalid date/time value" };
}
value[propertyName] = propertyValue;
}
} else if (property.type === "Edm.Time") {
value[propertyName] = parseDuration(propertyValue);
}
}
}
} else if (recognizeDates) {
for (var name in value) {
propertyValue = value[name];
if (typeof propertyValue === "string") {
value[name] = dateParser(propertyValue) || propertyValue;
}
}
}
}
return value;
};