Deserialize YML ignoring properties with lists
Describe the bug Weird behavior when deserialize YML ignoring properties and having lists. When a list of values is in YML file, it stops deserialization of values that are defined after that. I tried the same code in Java and there was no problem.
To Reproduce
val objectMapper = ObjectMapper(YAMLFactory()).registerKotlinModule()
val testYml: TestYml = objectMapper.readValue(
File(this.javaClass.classLoader.getResource("test_yml.yml").toURI()),
TestYml::class.java
)
println(testYml.name)
@JsonIgnoreProperties(ignoreUnknown = true)
data class TestYml(
val name: String?
)
When having test_yml.yml like:
name: containerNameTest
ports:
- 3306
This works fine, we can see the value of "name".
When having test_yml.yml like:
ports:
- 3306
name: containerNameTest
This doesn't work, "name" is null.
Expected behavior We should see value of "name" in both case.
Versions Kotlin: 1.4.20 Jackson-module-kotlin: 2.13.0-rc1 Jackson-databind: 2.13.0-rc1
This probably needs to go under jackson-dataformats-text repo. But if so, would need plain Java reproduction. I suspect this is not related to Kotlin.
One quick note tho: for testing, it's rarely if ever good to use this:
@JsonIgnoreProperties(ignoreUnknown = true)
since that very often hides real issues.
I tried with java doing:
public App() throws URISyntaxException, IOException {
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
File file = new File(this.getClass().getClassLoader().getResource("test_yml.yml").toURI());
TestYml testYml = objectMapper.readValue(file, TestYml.class);
System.out.println(testYml.getName());
}
public static void main(String[] args) throws URISyntaxException, IOException {
new App();
}
@JsonIgnoreProperties(ignoreUnknown = true)
public static class TestYml {
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
And this is working fine in both case.