- 
                Notifications
    
You must be signed in to change notification settings  - Fork 38.8k
 
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: bugA general bugA general bug
Milestone
Description
Andy Wilkinson opened SPR-16769 and commented
This is related to #19986, although I think this issue is a bug rather than an enhancement.
YamlPropertiesFactoryBean handles an entry with an empty value differently to an entry with a value that is an empty array. An empty value becomes an empty string in the resulting Properties whereas the entry with an empty array value doesn't appear in the Properties at all.
Here are four tests that show this difference in behaviour (as well as the behaviour of YamlMapFactoryBean:
	@Test
	public void mapWithEmptyArrayValue() throws IOException {
		YamlMapFactoryBean factory = new YamlMapFactoryBean();
		factory.setResources(new ByteArrayResource("a: alpha\ntest: []".getBytes()));
		factory.afterPropertiesSet();
		assertThat(factory.getObject()).containsKey("test");
	}
	@Test
	public void mapWithEmptyValue() throws IOException {
		YamlMapFactoryBean factory = new YamlMapFactoryBean();
		factory.setResources(new ByteArrayResource("a: alpha\ntest:".getBytes()));
		factory.afterPropertiesSet();
		assertThat(factory.getObject()).containsKey("test");
	}
	@Test
	public void propertiesWithEmptyArrayValue() throws IOException {
		YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
		factory.setResources(new ByteArrayResource("a: alpha\ntest: []".getBytes()));
		factory.afterPropertiesSet();
		assertThat(factory.getObject()).containsKey("test");
	}
	@Test
	public void propertiesWithEmptyValue() throws IOException {
		YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
		factory.setResources(new ByteArrayResource("a: alpha\ntest:".getBytes()));
		factory.afterPropertiesSet();
		assertThat(factory.getObject()).containsKey("test");
	}propertiesWithEmptyArrayValue fails due to the entry being lost.
Affects: 4.3.16, 5.0.5
Reference URL: spring-projects/spring-boot#12965
Issue Links:
- Allow to map null value from yaml [SPR-15425] #19986 Allow to map null value from yaml
 - YAML + PropertyPlaceholderConfigurer needs to process non-String values as well [SPR-14737] #19303 YAML + PropertyPlaceholderConfigurer needs to process non-String values as well
 - Restore YamlProcessor duplicate key handling against SnakeYAML 1.18+ (plus compatibility with 1.21) [SPR-16791] #21331 Restore YamlProcessor duplicate key handling against SnakeYAML 1.18+ (plus compatibility with 1.21)
 
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: bugA general bugA general bug