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

RandomOptionGenerator generates Option<Object> instead of actual Option<T> #416

Closed
araknafobia opened this issue May 10, 2020 · 2 comments
Closed
Labels
Milestone

Comments

@araknafobia
Copy link

As I explained in gitter https://gitter.im/j-easy/easy-random?at=5eb800d25cd4fe50a3ffea5f Optional fields generated by easy-random can not be casted to actual value of T.

You can simple do the followings to recreate the issue:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExampleClass {
    private Optional<String> a;
    private Optional<String> b;
}

ExampleClass e1 = easyRandom.nextObject(ExampleClass.class);
ExampleClass e2 = new ExampleClass(Optional.of("asd"), Optional.of("asd"));

System.out.println(e1);
// note that printed fields are Optional[Object]
ExampleClass(a=Optional[java.lang.Object@7675f6], b=Optional[java.lang.Object@3117145]) 

System.out.println(e2);
ExampleClass(a=Optional[asd], b=Optional[asd])

e2.getA().ifPresent(System.out::println);
// Prints the fields value successfully if A is Some
e1.getA().ifPresent(System.out::println);
class java.lang.Object cannot be cast to class java.lang.String (java.lang.Object and java.lang.String are in module java.base of loader 'bootstrap')
@mutyasaisrikar
Copy link

Is there a fix planned for this issue?

@fmbenhassine fmbenhassine added this to the 4.3.0 milestone Oct 20, 2020
@fmbenhassine
Copy link
Member

This should be fixed now. I would be grateful if you can give it a try in 4.3.0-SNAPSHOT and share your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants