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

Regression: PropertiesFactoryBean values do not get converted to target type without ConversionService [SPR-13256] #17847

Closed
spring-projects-issues opened this issue Jul 21, 2015 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Robert Thaler opened SPR-13256 and commented

After upgrading a project from Spring 3.1.4 to 4.1.6, values set from property files via PropertyFactoryBean do not get converted to the destination type anymore.

Sample:

content of enum.properties
level.warn=WARN
level.info=INFO
level.error=ERROR

enum Level { WARN, INFO, ERROR }

class TestBean {
private Map<String,Level> levelMap;

public void setLevelMap( Map<String,Level> levelMap ) {
	this.levelMap = levelMap;
}

}

Instead of the expected value type Level a map with String values is set by spring.


Affects: 4.1.6, 4.1.7

Attachments:

Referenced from: commits d4a23b8

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Could you try to isolate a test case for this, please? Binding to generically typed Maps does work in general, so it's probably something subtle in your overall arrangement...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Robert Thaler commented

Many thanks for your quick response.

I have uploaded a simple testcase that shows the problem - you can find and execute TestBeanTest located in src/test/sandbox.

kind regards
Robert

@spring-projects-issues
Copy link
Collaborator Author

Robert Thaler commented

I did some experiments with the testcase.
After configuring an additional ConversionServiceFactoryBean map values get converted properly.

Even if it works (for me), I am unsure if that is the way it should work because no ConversionServiceFactoryBean is necessary for Spring 3.1.4.

Robert

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

The problem here is the new implementation of TypeDescriptor.narrow in Spring 4.x, based on ResolvableType now: We're losing the originally declared key and value types when the type gets narrowed to java.util.Properties which is explicitly declared as Map<Object, Object> itself. This may show negative effects in other scenarios as well, so definitely needs to be fixed for 4.2.1 and 4.1.8.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

After further research, TypeDescriptor.narrow actually behaves as it should, in particular for its use with SpEL. Instead, it's BeanWrapper's TypeConverterDelegate which appears to pointlessly call narrow without any actual need to. I've removed those calls for 4.2.1 now but refrain from backporting this to 4.1.8 due to potential side effects.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2.1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants