Skip to content

Fix decoding single config values#102

Open
kusamakura wants to merge 1 commit intocirce:mainfrom
kusamakura:kusamakura/fix-decode-config-value
Open

Fix decoding single config values#102
kusamakura wants to merge 1 commit intocirce:mainfrom
kusamakura:kusamakura/fix-decode-config-value

Conversation

@kusamakura
Copy link
Copy Markdown

@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
Copy Markdown
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