j-easy/easy-random

Use getter instead of reflection

dgombert opened this issue · 1 comments

Hi,

In the ReflectionUtils class, the set and get of a value is treated differently. For the setter it is possible to use setter instead of reflection and this way is the default. But for the getter only the reflection way exist and it cause issues in my case.

I'm working on Java 11 with JPMS modules. One of my module contains all utility including methods using easy-random. My main method have a Class in parameters and return Json string. I use this method to generate sample Json from POJO. My POJOs are containing in all others modules. My POJOs have private fields with public getters and setters. Considering that Easy-random used reflection to get value of a field, i'm mandatory to open all POJO package to utility module and i think it's not properly. The set value behavior work fine with module, it's just the get of a value that take problem.

I have solve this problem in my fork with the commit dgombert@8418d0d.

Could you want me to create a pull request in this repository, if so tell me.

Thank you for opening this issue! Indeed, we can make ER provide a way to use getters or bypass them and use reflection instead. We would need to add a parameter similar to bypassSetters but for getters. I checked the change in your fork and it LGTM. You are welcome to open a PR, I will include it in the upcoming v6.

Thanks again for raising this and for your offer to help with a PR! Much appreciated.