json-immutable icon indicating copy to clipboard operation
json-immutable copied to clipboard

Deprecated record type option

Open jankuca opened this issue 6 years ago • 0 comments

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()) }

jankuca avatar Jan 06 '20 14:01 jankuca