Spring-boot: Add origin support for empty YAML list and map

Created on 12 Mar 2020  路  3Comments  路  Source: spring-projects/spring-boot

While searching the root cause for https://github.com/spring-cloud/spring-cloud-config/issues/1572 I reviewed OriginTrackedYamlLoader. In cases of an empty list or empty map there is no origin created.

Reproduction
Add to https://raw.githubusercontent.com/spring-projects/spring-boot/master/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/env/test-yaml.yml

emptylist: []
emptymap: {}

and extend testcases for emptylist and emptymap.

Fix
Add additional code for CollectionNodes which are empty In OriginTrackedYamlLoader.constructObject between ScalarNode and MappingNode check.

} else if (node instanceof CollectionNode && ((CollectionNode<?>) node).getValue().isEmpty()) {
   return constructTrackedObject(node, super.constructObject(node));
}

https://github.com/spring-projects/spring-boot/blob/a66c4d3096877b33119366ea9ea165c892b462c8/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java#L85-L95

superseded enhancement

Most helpful comment

It seems that @mbhave intended to close this.

All 3 comments

Closing in favor of PR #21704.

It seems that @mbhave intended to close this.

Thanks.

Was this page helpful?
0 / 5 - 0 ratings