Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

.fromJson accepts property or field name when field option is set on @Json #121

Open
etsuo opened this issue Jan 16, 2018 · 0 comments
Open

Comments

@etsuo
Copy link
Member

etsuo commented Jan 16, 2018

To be honest, I'm not sure if this is a bug or not. I can't remember if I made an intentional design decision about this.

Revaluate this to determine what the behavior should be.

Steps to reproduce: (see json.spec.ts test for bug #121)

      @Model({})
      class TestBug extends SapiModelMixin() {
        @Json({
          field: 'sp'
        })
        someProperty: string = 'default';
      }

      const result1 = TestBug.fromJson({sp: 'not-default-1'});
      expect(result1.someProperty).toBe('not-default-1');

      const result2 = TestBug.fromJson({someProperty: 'not-default-2'});
      expect(result2.someProperty).toBe('default');

result2 is set to not-default-2 instead of default even though the @Json decorator for someProperty expects the field to be sp.

If you provide sp, it works properly. The bug (? if it is a bug) is that someProperty also works when provided as a Json field to .fromJson.

Discovered when working on #96.

@etsuo etsuo added the bug label Jan 16, 2018
@etsuo etsuo added this to the 0.9.0 milestone Jan 16, 2018
@etsuo etsuo self-assigned this Jan 16, 2018
@etsuo etsuo added the verify label Jan 26, 2018
@etsuo etsuo modified the milestones: 0.9.0, 0.10.0 Jan 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant