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

Fix decoding single config values #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kusamakura
Copy link

@kusamakura kusamakura commented Jan 7, 2020

Decoding configuration keys one by one, in contrast to decoding the whole thing into a case class, always results in an error:

import com.typesafe.config.ConfigFactory
import io.circe.config.parser

val config = ConfigFactory.parseString("a = 1")
// Returns: Left(io.circe.ParsingFailure: String: 1: a has type NUMBER rather than OBJECT)
// Expected: Right(1)
parser.decodePath[Int](config, "a")

The problem stems from the Config#root call in the toJson method in the parser, where a pathed Config may hold a string, and int, etc., and thus is not a ConfigObject. The fix is to call Config#getValue(path) when the path is present, and Config#root otherwise.

Calling `Config#root` on a pathed Config casts it into a ConfigObject,
even when it is not. The fix is to call `root` only on the unpathed config.
@travisbrown
Copy link
Member

This looks reasonable to me but I'll defer to @jonas.

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

Successfully merging this pull request may close these issues.

2 participants