Skip to content

Wrong value parsed when having a key that starts with the value of another key using hyphens #82

@fmeeuw

Description

@fmeeuw

When having both foo-bar and foo present in a case class, Ficus attempts to parse the value of foo-bar and assign it to foo. When they both have different types this results in a ClassCastException, however when the types are the same, ficus will assign the value of foo-bar to both foo and foo-bar.

Example that fails with ClassCastException.

import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import com.typesafe.config._

case class TestSettings(val `foo-bar`: Long, `foo`: String)

val config = ConfigFactory.parseString("""{ foo-bar: 3, foo: "4" }""")
val settings = config.as[TestSettings] // throws java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String!

Example that doesn't fail, but assigns the value of foo-bar to foo.

case class TestSettings2(val `foo-bar`: String, `foo`: String)

val config = ConfigFactory.parseString("""{ foo-bar: "foo-bar", foo: "foo" }""")
val settings = config.as[TestSettings2]
println(settings.`foo-bar`) // prints out foo-bar
println(settings.foo) // also prints out foo-bar!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions