Skip to content
Discussion options

You must be logged in to vote

@gabryellr if i understand correctly, your classes can contain multiple CodeDto fields:

class Example {
    CodeDto foo;
    CodeDto bar;
    //...
}

There's no workaround that i can think of that doesn't require using scopes. One option is to create a utility selector like this:

public class SelectCode {
    public static <T,R> TargetSelector of(ScopeableSelector selector) {
        final Scope scope = selector.toScope();
        return Select.field(CodeDto::getCode).within(scope);
    }
}

// Usage:
var result = Instancio.of(Example.class)
    .set(SelectCode.of(field(Example::getFoo)), "foo")
    .set(SelectCode.of(field(Example::getBar)), "bar")
    .create();

You could also name the …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@gabryellr
Comment options

@armandino
Comment options

Answer selected by gabryellr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants