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

as[Map[String, ConfigValue]] on root config fails #56

Open
woky opened this issue Nov 3, 2017 · 5 comments
Open

as[Map[String, ConfigValue]] on root config fails #56

woky opened this issue Nov 3, 2017 · 5 comments

Comments

@woky
Copy link

woky commented Nov 3, 2017

With typesafe config 1.3.2, as on root config object fails. Example:

import com.typesafe.config.{ConfigFactory, ConfigValue}
import net.ceedubs.ficus.Ficus._

val config = ConfigFactory.parseString(
  """
foo = {
  x = 1
  y = [ 0.1 2 ]
  z = {
    a = 2
  }
}
baz = [1 2 3]
""")

// fine
val submap = config.as[Map[String, ConfigValue]]("foo")

// Exception in thread "main" com.typesafe.config.ConfigException$BadPath: path parameter: Invalid path '.': path has a leading, trailing, or two adjacent period '.' (use quoted "" empty string if you want an empty element)
val map1 = config.as[Map[String, ConfigValue]]

// same as above
val map2 = config.as[Map[String, ConfigValue]]("")

Here's the scaste: https://scastie.scala-lang.org/9VG0LqRGQzmbCQ00OHxqfw

Full error:

Exception in thread "main" com.typesafe.config.ConfigException$BadPath: path parameter: Invalid path '.': path has a leading, trailing, or two adjacent period '.' (use quoted "" empty string if you want an empty element)
	at com.typesafe.config.impl.PathParser.parsePathExpression(PathParser.java:170)
	at com.typesafe.config.impl.PathParser.parsePathExpression(PathParser.java:74)
	at com.typesafe.config.impl.PathParser.parsePath(PathParser.java:61)
	at com.typesafe.config.impl.Path.newPath(Path.java:230)
	at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:192)
	at com.typesafe.config.impl.SimpleConfig.getObject(SimpleConfig.java:268)
	at com.typesafe.config.impl.SimpleConfig.getConfig(SimpleConfig.java:274)
	at com.typesafe.config.impl.SimpleConfig.getConfig(SimpleConfig.java:41)
	at net.ceedubs.ficus.readers.CollectionReaders$$anon$2.read(CollectionReaders.scala:28)
	at net.ceedubs.ficus.readers.CollectionReaders$$anon$2.read(CollectionReaders.scala:26)
	at net.ceedubs.ficus.FicusConfig.as(FicusConfig.scala:10)
	at net.ceedubs.ficus.FicusConfig.as$(FicusConfig.scala:10)
	at net.ceedubs.ficus.SimpleFicusConfig.as(FicusConfig.scala:21)
	at net.ceedubs.ficus.FicusConfig.as(FicusConfig.scala:12)
	at net.ceedubs.ficus.FicusConfig.as$(FicusConfig.scala:12)
	at net.ceedubs.ficus.SimpleFicusConfig.as(FicusConfig.scala:21)
	at fed.FicusRoot$.delayedEndpoint$fed$FicusRoot$1(FicusRoot.scala:25)
	at fed.FicusRoot$delayedInit$body.apply(FicusRoot.scala:7)
	at scala.Function0.apply$mcV$sp(Function0.scala:34)
	at scala.Function0.apply$mcV$sp$(Function0.scala:34)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
	at scala.App.$anonfun$main$1$adapted(App.scala:76)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at scala.App.main(App.scala:76)
	at scala.App.main$(App.scala:74)
	at fed.FicusRoot$.main(FicusRoot.scala:7)
	at fed.FicusRoot.main(FicusRoot.scala)

I'm currently getting familiar with the library. Possible use case would be mapping the whole config to a simple case class. I think I saw in the README that mapping to arbitrary classes is supported.

@kailuowang
Copy link
Member

Yes it should work for a case class which is the main point of ficus

@woky
Copy link
Author

woky commented Nov 3, 2017

I've just tried. On case class it works perfectly even without dummy root. It's amazing!

@woky woky changed the title as on root config fails as[Map[String, ConfigValue]] on root config fails Nov 4, 2017
@kailuowang
Copy link
Member

Glad it worked out.

@javadba
Copy link

javadba commented May 24, 2018

maybe this should be closed?

@woky
Copy link
Author

woky commented Jun 6, 2018

I think it still doesn't work for the reported case (Map[String, ConfigValue]). It works for custom case classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants