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

Errors.rejectValue doesn't accept specific fields on subclass when List entry is declared as base class [SPR-11784] #16406

Closed
spring-projects-issues opened this issue May 14, 2014 · 2 comments
Labels
status: bulk-closed

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented May 14, 2014

Michael Z opened SPR-11784 and commented

I get Exception

org.springframework.beans.NotReadablePropertyException: Invalid property 'entries[0].reason' of bean class [my.company.data.SDROrder]: Bean property 'entries[0].reason' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

from the following code snippet:

Errors errors = new BeanPropertyBindingResult(new SDROrder(), "sdr");
orderValidator.validate(order, errors);

for validator:

    public class OrderValidator implements Validator
    {

        @Override
        public boolean supports(Class<?> clazz)
        {
            return Order.class.isAssignableFrom(clazz);
        }

        @Override
        public void validate(final Object target, final Errors errors)
        {
            errors.rejectValue("entries[0].reason", "Wrong Reason");
        }

    }

where we have such data hierarchy

    public class Order
    {
        private List<AbstractOrderEntry> entries;

        public List<AbstractOrderEntry> getEntries()
        {
            return entries;
        }

        public void setEntries(List<AbstractOrderEntry> entries)
        {
            this.entries = entries;
        }
    }

    public class SDROrder extends Order
    {

    }

    public class AbstractOrderEntry
    {

    }

    public class SDROrderEntry extends AbstractOrderEntry
    {
        private String reason;

        public String getReason()
        {
            return reason;
        }

        public void setReason(String reason)
        {
            this.reason = reason;
        }
    }

Please see working example here: https://github.com/ZPetrovich/SpringValidationInheritance

Just to clarify. The problem is I try to rejectValue on object that has Collection of objects where each element has specific attribute at Runtime but has not it at Compile time. Spring uses Bean's properties to resolve these fields and can't find inherited attribute. The question is: can I explain Spring to resolve inherited fields somehow?


Affects: 3.1.4

Reference URL: https://github.com/ZPetrovich/SpringValidationInheritance

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 4, 2014

Michael Z commented

Workaround found. Just use pushNested/popNested to achieve described goal. Anyway it would be great to have this support without this sophisticated mechanism.
Thanks!

@spring-projects-issues spring-projects-issues added status: waiting-for-triage type: enhancement and removed type: enhancement labels Jan 11, 2019
@rstoyanchev rstoyanchev added status: bulk-closed and removed status: waiting-for-triage labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 12, 2019

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

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

No branches or pull requests

2 participants