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

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

Closed
spring-projects-issues opened this issue Apr 25, 2018 · 2 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

spring-projects-issues commented Apr 25, 2018

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

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

There is a candidate fix but I am not entirely sure that we should backport that behaviour change.

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

After more thoughts, I think we should have a fix in 5.0.x for this so I've backported it so that it can be consumed by the upcoming Spring Boot 2.0.2.RELEASE.

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