-
Notifications
You must be signed in to change notification settings - Fork 1
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
Objects with interface types fields doesn't get the concrete implementations of fields populated #6
Comments
The main example of this issue is when creating objects with fields of type Collection, Set or Map. We instantiate those fields with a default concrete implementation but those instance doesn't have any data. |
To get this to work (generate random values) we would still need to get the Generic Type of the Collection. Would you have any suggestions for this implementation ? |
One way that I thought was having a map of interfaces and the prefered concrete implementation class that would be used. Another option would be scanning the classpath to find eligible concrete implementations of an interface and picking the first one based on some criteria (alphabetically, for example). Also, it is important to give the user the opportunity to add their own interfaces and override the default mapping when desired.
This is a good point. How can we go around the type erasure? One last option could be creating an annotation that would take the concrete class and the generic type. This is not my favourite because it is quite intrusive in the code, but maybe we can have something as a last resort. |
I would think the user can create a custom implementation map before building objects.
Still wondering :) |
Really interesting article. I'll read it completely during the weekend and check if I find a way on how to apply this pattern in the project. Let me know if you come up with something as well! |
I think I found a way to do it. I'll try it on the weekend (feel free to try as well, as I might not find time this weekend).
I'll play a little bit with it to see what I can do. |
This issue only affects the random object generation (with random data). For the fixture based generation it all goes well.
For now Playdoh will create objects with interface types but wont populate those concrete types. E.g. if the object has a Set type field, Playdoh will create an empty set when generating the object.
We need to make Playdoh populate those fields with data.
The text was updated successfully, but these errors were encountered: