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

Add java object transformer #513

Merged
merged 1 commit into from Jan 12, 2023
Merged

Add java object transformer #513

merged 1 commit into from Jan 12, 2023

Conversation

snuyanzin
Copy link
Collaborator

@snuyanzin snuyanzin commented Nov 1, 2022

Another transformer which could fill java objects
e.g. this will generate a collection of Person objects according to schema

JavaObjectTransformer jTransformer = new JavaObjectTransformer();
        Schema<Object, ?> schema = Schema.of(
            field("firstName", () -> faker.name().firstName()),
            field("lastName", () -> faker.name().lastName()),
            field("birthDate", () -> faker.date().birthday()),
            field("id", () -> faker.number().positive()));

        Collection<Person> persons = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            persons.add(jTransformer.apply(Person.class, schema));
        }

full example is here https://github.com/datafaker-net/datafaker/pull/513/files#diff-b7465230f153bf0f00c1788b28aeb4a239eac7c4438819f5bf6134943b993177R13-R42

cc @bodiam since you were looking for something like that afair

@bodiam
Copy link
Contributor

bodiam commented Nov 3, 2022

Nice. I'm still a bit more a fan of what EasyRandom does, eg if you have a structure like this:

data class Person(val addresses: List<Address>)

data class Address(val street: String, val city: String, val country: String)    

That we can generate something by doing:

val person = faker.populate(Person())

@bodiam
Copy link
Contributor

bodiam commented Jan 12, 2023

@snuyanzin what do you want to do with this PR?

@snuyanzin
Copy link
Collaborator Author

let's merge it

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

Successfully merging this pull request may close these issues.

None yet

2 participants