Skip to content

BeanWrapper does not support objects that are maps/arrays/lists them-selves [SPR-2058] #6751

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No 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? No Sign in to your account

Closed
spring-projects-issues opened this issue May 25, 2006 · 3 comments
Assignees
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

Alex Antonov opened SPR-2058 and commented

When a BeanWrapper wraps an object that is a map or a collection of sorts, it has trouble retrieving a value using a key property
i.e.
Person p = new Person("John");
Map map = new HashMap();
map.put("key", person);
BeanWrapperImpl wrapper = new BeanWrapperImpl(map);
String name = wrapper.getPropertyValue("[key].name")

This kind of access is very possible when comming from a web-layer using a bind-path of something like [key].name when the top-level object is itself a map.
In this case, when calling errros.rejectValue("[key].name", ...) in the validator, the call throws an exception due to inability to find an object referenced by [key].

Currently a work-around this problem is to subclass a map and provide a getter for every key you might have in the map, so that the path looks like key.name, but
this approach requires a lot of overhead of the getter creation.


11 votes, 9 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

IMO, this does not qualify as a bug - it's rather a well-known, intentional limitation. We can of course reconsider whether we actually want to support Collection/Map objects directly, despite them not actually being JavaBeans.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Dave Syer commented

I think it would be useful, especially in web apps, especially when prototyping.

I believe commons-beanutils PropertyUtils works sort of in the way described above, so people may already be used to it.

The only difficult decision I can see is what to do with properties that are not already keys in the map. In commons-beanutils if I do PropertyUtils.getProperty(map,"key") I get null irrespective of whether the key already existed. Maybe I would prefer it to barf with an invalid property exception. This would make the behaviour BeanWrapper more consistent between the map and non-map cases.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Closing groups of outdated issues. Please reopen if still relevant.

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import labels Jan 10, 2019
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants