-
Notifications
You must be signed in to change notification settings - Fork 179
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
Java Object transformation to list #979
Comments
you could use List<DefaultPerson> list = new FakeCollection.Builder<DefaultPerson>()
.suppliers(() -> Faker.populate(DefaultPerson.class)).generate();
System.out.println(list); so in your case it could be something like Faker faker = new Faker();
Schema<Object, ?> schema = Schema.of(
Field.field("name", () -> faker.name().firstName()),
Field.field("email", () -> faker.internet().emailAddress())
);
BaseFaker bfaker = new BaseFaker();
List<Client> list = new FakeCollection.Builder<Client>()
.suppliers(() -> Faker.populate(Client.class, schema)).len(<min>, <max>).generate(); |
@snuyanzin Thanks for the feedback. List<Client> client = new FakeCollection.Builder<Client>().suppliers(()
-> Faker.populate(Client.class, schema))
.len(5).generate();
client2.forEach((t) -> {
System.out.println(t.getName() + " " + t.getEmail());
}); Output
Although it works with simple Collection generation List<String> names =
faker.collection(
() -> faker.name().firstName(),
() -> faker.name().lastName())
.len(5)
.generate(); Output
|
Can you share the complete code snippet? |
Hi @albilu , could you give the snapshot release a try? |
Is Java object transformation to list possible??
From the documentation here https://www.datafaker.net/documentation/schemas/#java-object-transformation it seems only singleton is posssible unless i missed something.
Please advise. Here is my iomplementation:
The text was updated successfully, but these errors were encountered: