Skip to content

YamlPropertiesFactoryBean loses entries in the YAML document that have an empty array value [SPR-16769] #21310

@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 43f2334, e51330e

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions