json-immutable
json-immutable copied to clipboard
Deprecated record type option
Listing a record type in the new deprecatedRecordTypes option of deserialization will not make the process fail on encountering such unknown record and instead will remove the associated key from the result.
const result = deserialize('{
"a": { "__record": "Deprecated" },
"b": "preserved data"
}', {
deprecatedRecordTypes: [ 'Deprecated' ],
})
// -> { 'b': 'preserved data' }
Beware that deprecating a record used in an array or an immutable List/Set/Stack will not remove the item from the collection but rather leave an undefined value:
const result = deserialize('{
"items": {
"__iterable": "List",
"data": [
{ "__record": "MyRecord" },
{ "__record": "Deprecated" },
{ "__record": "MyRecord" }
]
}
}', {
recordTypes: { 'MyRecord': MyRecord },
deprecatedRecordTypes: [ 'Deprecated' ],
})
// -> { 'items': List.of(MyRecord(), undefined, MyRecord()) }