class-transformer
class-transformer copied to clipboard
question: Exclude property of type
Is it possible to exlude a property of nested object? For example:
export class Foo {
public prop1: string;
public prop2: string;
public prop3: string; // <== Property to exclude
}
export class Bar {
@Type(() => Foo)
public prop: Foo[];
}
I can't use @Exclude() decorator because I need to exclude the property only in the Bar class and not in the other classes that extends Foo.
read docs about expose groups
@AmedeoD96 is it working for you?
export class User { @OneToOne(() => Profile, (profile) => profile.user) @JoinColumn() @Expose({ groups: [GROUP_ME] }) profile: Profile; } export class Profile { @PrimaryGeneratedColumn('uuid') @Expose({ groups: [GROUP_ME] }) id: string; }
Response is
"profile": {},
If I remove the @expose from the profile returns the id