-
Notifications
You must be signed in to change notification settings - Fork 497
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
fix: @Expose decorator exposes class property names when working with Maps #319
Comments
We are encountering this issue as well. Using |
It appears that when adding class Weapon {
@Expose() name: string;
@Expose() range: number;
}
class Player {
@Expose() name: string
@Expose()
@Type(() => Weapon)
weapons: Map<string, Weapon>;
}
const json = {
name: "name",
weapons: {
"w1": { name: "weapon1", range: 1 },
"w2": { name: "weapon2", range: 2}
}
};
console.log(
plainToClass(Player, json, {
excludeExtraneousValues: false,
})
) Result Player {
name: 'name',
weapons: Map {
'w1' => Weapon { name: 'weapon1', range: 1 },
'w2' => Weapon { name: 'weapon2', range: 2},
'name' => undefined,
'range' => undefined
}
}
'name' => undefined,
'range' => undefined
class Weapon {
@Expose() name: string;
@Expose() range: number;
}
class Player {
@Expose() name: string;
@Expose()
@Type(() => Weapon)
weapons: Map<string, Weapon>;
}
const json = {
name: "name",
weapons: {
"w1": { name: "weapon1", range: 1 },
"w2": { name: "weapon2", range: 2}
}
};
console.log(
plainToClass(Player, json, {
excludeExtraneousValues: true,
})
);
}); Result Player {
weapons: Map { 'name' => undefined, 'range' => undefined }
} |
This has been fixed in develop via #405 and be included in the next release. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Output:
Expected output:
The text was updated successfully, but these errors were encountered: