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

ValidationStatus#getMessages return value has changed #415

Closed
gtnarg opened this issue Jun 30, 2016 · 5 comments
Closed

ValidationStatus#getMessages return value has changed #415

gtnarg opened this issue Jun 30, 2016 · 5 comments
Labels
Milestone

Comments

@gtnarg
Copy link

gtnarg commented Jun 30, 2016

I have subclassed ValidationMessage and am using them in a CompositeValidator, This previously worked. As of 1.5.2, the following code fails:

List<MyValidationType> validationMessages = compositeValidator.getValidationStatus().getMessages();

with the following error:

de.saxsys.mvvmfx.utils.validation.CompositeValidationStatus$CompositeValidationMessageWrapper cannot be cast to mypackage.MyValidationMessage

Is there any way to get access to the actual validation messages?

@manuel-mauky
Copy link
Collaborator

Sorry for the problem. I haven't had such use case in mind when I was refactoring the Composite Validator. I assume the problem came up with 1.5.1 and this issue #398 and this fix #401.

manuel-mauky added a commit that referenced this issue Jul 1, 2016
Due to a change in 1.5.1 it wasn't possible to use subclasses of ValidationMessage together with CompositeValidator anymore.
The reason was an internal refactoring of the CompositeValidationResult class.
In this commit the class was refactored again and now uses another logic to both fix the original bug and still make
usage of custom ValidationMessage types possible.

Fix for #415
@manuel-mauky
Copy link
Collaborator

manuel-mauky commented Jul 1, 2016

Hi,
I've refactored the CompositeValidationStatus class. It now uses another approach instead of a wrapper class. I've added a test case that shows the usage of a Custom validationMessage type too.

I hope this solves your problem.

However the actual code you provided doesn't compile and I think it wasn't compiling in previous versions neither because the return type of ValidationStatus.getMessages() is (and always was) ObservableList<ValidationMessage>. This can't be casted to List<MyValidationType> due to java's poor type system.
However it's possible to cast actual instances inside the list (this is now possible again). Your code could look like this:

List<MyValidationType> validationMessages = 
    compositeValidator.getValidationStatus().getMessage()
    .stream()
    .map(m -> (MyValidationType) m) // this wasn't possible
    .collect(Collectors.toList());

@sideisra Can you review the code and test it in your project? All tests are green but maybe there are still corner cases for which we don't have test cases yet.

@gtnarg
Copy link
Author

gtnarg commented Jul 1, 2016

I have tested it, and it is working correctly on my side. Thanks for the quick response :)

Sorry, I had sanitized my code for the purposes of explaining the problem - the actual code is:

    public ObservableList<MyValidationMessage> getValidationMessages(){
        return EasyBind.map( getValidationStatus().getMessages(),
                validationMessage -> (MyValidationMessage)validationMessage);
    }

which is consistent with your example.

@sideisra
Copy link
Contributor

sideisra commented Jul 4, 2016

@lestard looks good 👍

@manuel-mauky
Copy link
Collaborator

Ok cool. So I will merge this with develop so it can be tested with version 1.6.0-SNAPSHOT.

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