Skip to content

Record fields still being generated even if randomizer is specified for field to set it to null #39

Open
@jamesforward999

Description

@jamesforward999

Given a record like:

public record MyRecord(String fieldOne, AnotherRecord fieldTwo) {}

where AnotherRecord is a record

When I do:

easyRandomParameters.randomize(
            field -> field.equals(fieldTwoField), () -> null
        );

I would expect the value for fieldTwo to be null. This works with most primitives & other classes that are not records. However, with records, fieldTwo is not null and still subject to value generation.

I've sort of worked around this by also adding:

easyRandomParameters.randomize(AnotherRecord.class, new SkipRandomizer());

however if in my object I have more than one field that is AnotherRecord, ie:

public record SomeOtherRecord(AnotherRecord fieldOne, AnotherRecord fieldTwo) {}

naturally both fieldOne & fieldTwo would be skipped, so it doesn't work in those scenarios. The intention is just to null out that single field (fieldTwo).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions