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

Predicate to control overrideDefaultInitialization #506

Open
tomas0svk opened this issue Aug 23, 2023 · 0 comments
Open

Predicate to control overrideDefaultInitialization #506

tomas0svk opened this issue Aug 23, 2023 · 0 comments

Comments

@tomas0svk
Copy link

Please can you give me an idea how to control overrideDefaultInitialization to certain fields by filter (like excludeField or randomize do), to achieve something like:

.overrideDefaultInitialization(
      FieldPredicates.ofType(String.class).negate()
)

The problem is, that we are using generated classes, where generators often initialize collections right at the declaration point such as
List<Foo> bar = new ArrayList<>().
These are treated as already initialized and thus are not randomized.

I could set overrideDefaultInitialization(true), but there is a problem of randomizing other fields with useful initial value, most often String constants.
I was able to control this to some point by precisely finding them and excluding such fields, e.g.

.excludeField(
    FieldPredicates.ofType(String.class)
     .and(FieldPredicates.named("objectType")
    .and(FieldPredicates.isAnnotatedWith(JsonProperty.class)))
)

but you understand this being very time consuming and tricky.

Thank you very much

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

No branches or pull requests

1 participant