Skip to content

Add support for callbacks in deserialization lifecycle #16

@noemi-salaun

Description

@noemi-salaun

We should add support for deserlization callbacks, something like

interface Deserializable {
   beforeDeserialize(event);
   afterDeserialize(event);
}

class Foo implements Deserializable {
   attr1: string;

   @DeserializeAs(Bar)
   attr2: Bar;

   beforeDeserialize(event) {
       event.json.attr1 = event.json.attr1 + '-modified';
   }

   afterDeserialize(event) {
      event.target.attr2.setSomething(event.json.something);
   }
}

We should also support function in place of class inside @DeserializeAs decorator.

const myFunc = (json) => {
    return json.someAttr + ' - ' + json.someOtherAttr;
}

class Foo {
    attr1: string;
 
    @DeserializeAs(myFunc)
    attr2: Bar;
}

All the proposed signature are fakes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions