-
Notifications
You must be signed in to change notification settings - Fork 198
Add annotation support for data classes based on JavaObjectTransformer #754
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
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #754 +/- ##
============================================
- Coverage 92.86% 92.85% -0.02%
- Complexity 2595 2606 +11
============================================
Files 281 282 +1
Lines 5127 5161 +34
Branches 530 533 +3
============================================
+ Hits 4761 4792 +31
- Misses 240 243 +3
Partials 126 126
... and 5 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
0972cd4
to
06738a7
Compare
src/test/java/net/datafaker/annotations/FakeAnnotationTest.java
Outdated
Show resolved
Hide resolved
src/test/java/net/datafaker/annotations/FakeAnnotationTest.java
Outdated
Show resolved
Hide resolved
68e66bb
to
448bce3
Compare
448bce3
to
1d5bafb
Compare
src/test/java/net/datafaker/annotations/FakeAnnotationTest.java
Outdated
Show resolved
Hide resolved
1d5bafb
to
9f8125f
Compare
thanks for your contribution @RVRhub //cc @bodiam since you mentioning something about that var person = Faker.populate(Person.class);
// or
var person2 = Faker.populate(Person.class, customSchema()); schema could be defined separately |
@snuyanzin's sorry, I missed some of the conversions on this. Is the annotation support now dropped in favor of some schema method? I'm not a huge fan of that schema support. I find it too hard to get the syntax correct, and I struggled to get the generics work. With the schema support it seems the connection between the fields and the generator is gone, as in I can't see which fields are using which generator, something which could be easily seen when you have annotated fields. So, what was the reason to pick an option like this over the annotation approach? |
There are 2 reasons After having several chats and POCs with @RVRhub we faced 2 issues:
To address these issues we decided to have only one annotation The idea is to build the solution based on java transformers approach #513 which already can generate objects. So the objects could be generated in 2 ways: MyClass object = Faker.populate(MyClass.class); this will generate an object with usage of default schema mentioned by MyClass object = Faker.populate(MyClass.class, myschema); this will allow to generate objects based on others schemas. In this way it's possible to have a number of different schemas and generate objects based on them. |
Okay, makes sense. Thanks for the clarification! |
docs/documentation/schemas.md
Outdated
Then you can use `net.datafaker.providers.base.BaseFaker.populate(java.lang.Class<T>)` to populate object with default predefined schema. | ||
Or you can use `net.datafaker.providers.base.BaseFaker.populate(java.lang.Class<T>, net.datafaker.schema.Schema<java.lang.Object, ?>)` to populate object with custom schema. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need code snippets for both cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one more snippet of object template population with custom schema
Co-authored-by: Sergey Nuyanzin <sergey.nuyanzin@aiven.io>
…akeForSchema annotation
datafaker-net#754) --------- Co-authored-by: Sergey Nuyanzin <sergey.nuyanzin@aiven.io>
PR adds annotation support for data class based on issue: #675
After some discussion, the idea came up to:
An example of usage
Data class definition:
Schema definition:
Object generation with default schema:
Object generation with custom schema: