Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bidirectional mapping with getter & setter #334

Closed
andzno1 opened this issue Aug 19, 2021 · 1 comment
Closed

Bidirectional mapping with getter & setter #334

andzno1 opened this issue Aug 19, 2021 · 1 comment

Comments

@andzno1
Copy link

andzno1 commented Aug 19, 2021

Describe the bug
This issue is related to issue #51.

I am not sure if the behavior I am expecting is actually the expected behavior. Looking at issue #51 lets me believe that it is.

When mapping an instance of a class Foo with a private property _foo that is being accessed via getter and setter to class FooDto that has a simple property foo, the mapping is done correctly. Mapping back from FooDto to Foo does not work with the @AutoMap() annotation, though.

Models/DTOs

class Foo {
  private _foo: number = NaN;

  @AutoMap()
  public get foo(): number {
    return this._foo;
  }

  public set foo(value: number) {
    this._foo = value;
  }
}

class FooDto {
  @AutoMap()
  public foo?: number;
}

Mapping Configuration

const mapper = createMapper({
  name: 'autoMapper',
  pluginInitializer: classes,
  namingConventions: new CamelCaseNamingConvention()
});

mapper.createMap(Foo, FooDto);
mapper.createMap(FooDto, Foo);

To Reproduce

const foo = new Foo();
foo.foo = 1337;

const fooDto = mapper.map(foo, FooDto, Foo);
const foo2 = mapper.map(fooDto, Foo, FooDto);

Expected behavior
Property foo2._foo is set to 1337.

Actual behavior
Property foo2._foo is set to null.

Minimal running example
https://stackblitz.com/edit/typescript-4jqllg?devtoolsheight=33&file=index.ts

@nartc nartc closed this as completed in 15ad713 Aug 22, 2021
@nartc
Copy link
Owner

nartc commented Aug 23, 2021

This has been fixed in 6.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants