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

[BUG] Groups deserialization is not working with collection #1723

Closed
Grutula opened this issue Jan 13, 2022 · 5 comments · Fixed by #1750
Closed

[BUG] Groups deserialization is not working with collection #1723

Grutula opened this issue Jan 13, 2022 · 5 comments · Fixed by #1750

Comments

@Grutula
Copy link

Grutula commented Jan 13, 2022

Information

  • Version: 6.98.0

@Groups("group") is used to omit some properties before accessing the controller (during the deserialization).
But in my case it does not work with an array

Example

import { deserialize } from "@tsed/json-mapper";
import { CollectionOf, Groups } from "@tsed/schema";

export class CustomRequest {
    @CollectionOf(String)
    @Groups("creation")
    a?: string[];

    @Groups("creation")
    b?: string;
}

const req = new CustomRequest();
req.a = ["a"];
req.b = "b";
const res = deserialize(req, { type: CustomRequest, groups: ["update"] });
console.log(JSON.stringify(res)); // {"a":["a"]}

@Romakita
Copy link
Collaborator

Romakita commented Feb 1, 2022

Hum your example is a bit strange? You create an object with the class and then you deserialize it? why ?

@Romakita
Copy link
Collaborator

Romakita commented Feb 1, 2022

🎉 This issue has been resolved in version 6.100.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Grutula
Copy link
Author

Grutula commented Feb 1, 2022

Hum your example is a bit strange? You create an object with the class and then you deserialize it? why ?

Hum yes sorry if the example was confusing 😅 I was reading the documentation and just try to put less lines as possible to target my problem efficently

import {deserialize} from "json-schema";

const result = deserialize({
  id: "id", // will be ignored because creation doesn't include `id` field
  firstName: "firstName",
  lastName: "lastName",
  email: "[email protected]",
  password: "password"
}, {type: User, groups: ['creation']});

console.log(result); // User {firstName, lastName, email, password}

But yes indeed it may be confusing because I didn't explain it and use an instance of my object directly

Thanks for you're release 🚀

@Romakita
Copy link
Collaborator

Romakita commented Feb 1, 2022

You’re welcome ;)

@Romakita
Copy link
Collaborator

🎉 This issue has been resolved in version 7.0.0-beta.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants