Skip to content

Commit

Permalink
Add comment explaining the usage of SafeConstructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ruippeixotog committed Jul 29, 2018
1 parent 6b8eaf9 commit 866aa34
Showing 1 changed file with 8 additions and 0 deletions.
Expand Up @@ -95,6 +95,8 @@ package object yaml {
def loadYaml[Config](path: Path)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] = {
handleYamlErrors(Some(path)) {
using(Files.newBufferedReader(path)) { ioReader =>
// we are using `SafeConstructor` in order to avoid creating custom Java instances, leaking the PureConfig
// abstraction over SnakeYAML
val yamlObj = new Yaml(new SafeConstructor()).load(ioReader)

yamlObjToConfigValue(yamlObj).right.flatMap { cv =>
Expand All @@ -113,6 +115,8 @@ package object yaml {
*/
def loadYaml[Config](content: String)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] = {
handleYamlErrors(None) {
// we are using `SafeConstructor` in order to avoid creating custom Java instances, leaking the PureConfig
// abstraction over SnakeYAML
val yamlObj = new Yaml(new SafeConstructor()).load(content)

yamlObjToConfigValue(yamlObj).right.flatMap { cv =>
Expand Down Expand Up @@ -161,6 +165,8 @@ package object yaml {
def loadYamls[Config](path: Path)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] = {
handleYamlErrors(Some(path)) {
using(Files.newBufferedReader(path)) { ioReader =>
// we are using `SafeConstructor` in order to avoid creating custom Java instances, leaking the PureConfig
// abstraction over SnakeYAML
val yamlObjs = new Yaml(new SafeConstructor()).loadAll(ioReader)

yamlObjs.asScala.map(yamlObjToConfigValue)
Expand All @@ -184,6 +190,8 @@ package object yaml {
*/
def loadYamls[Config](content: String)(implicit reader: Derivation[ConfigReader[Config]]): Either[ConfigReaderFailures, Config] = {
handleYamlErrors(None) {
// we are using `SafeConstructor` in order to avoid creating custom Java instances, leaking the PureConfig
// abstraction over SnakeYAML
val yamlObjs = new Yaml(new SafeConstructor()).loadAll(content)

yamlObjs.asScala.map(yamlObjToConfigValue)
Expand Down

0 comments on commit 866aa34

Please sign in to comment.