Skip to content

Predicate to control overrideDefaultInitialization #506

@tomas0svk

Description

@tomas0svk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions