Make null/undefined values deserialize correctly, especially for optional fields

master
Sven Slootweg 6 years ago
parent b4b625065a
commit 1ddafb60ef

@ -10,6 +10,8 @@ function isReference(serializedData) {
return (serializedData != null && serializedData._d_sT === "cTR"); return (serializedData != null && serializedData._d_sT === "cTR");
} }
/* FIXME: Pass both key and value to custom deserializer */
module.exports = function createDeserializer(topLevelType, topLevelData, typeMap, options = {}) { module.exports = function createDeserializer(topLevelType, topLevelData, typeMap, options = {}) {
let seen = new Map(); let seen = new Map();
let placeholders = createPlaceholderManager(); let placeholders = createPlaceholderManager();
@ -61,7 +63,9 @@ module.exports = function createDeserializer(topLevelType, topLevelData, typeMap
} }
function deserializeEntry(rule, serializedData) { function deserializeEntry(rule, serializedData) {
if (rule._isCustomType) { if (serializedData == null) {
return customDeserializer(serializedData);
} else if (rule._isCustomType) {
return deserializeInstanceOrReference(rule, serializedData); return deserializeInstanceOrReference(rule, serializedData);
} else if (rule._isCustomRegistryType) { } else if (rule._isCustomRegistryType) {
return deserializeInstanceOrReference(rule._registry._getType(rule._name), serializedData); return deserializeInstanceOrReference(rule._registry._getType(rule._name), serializedData);

Loading…
Cancel
Save