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
Remove the RawConfig type #28
Remove the RawConfig type #28
Conversation
This is interesting because I was working on something similar but I didn't have time to complete. Mine is also a bit more complex than this but your solution of working with @leifwickland maybe you are interested in this PR, it's quite the improvement compared to what we have right now in |
Sure! No problem!
Current implementations of I did a quick test, and this seems to fix #29. |
@melrief I really like the idea of this change. It fits with the initial expectation I had when I walked into the project. I think using typesafe's @jcazevedo Thanks for doing this! |
})) | ||
} | ||
|
||
def fromString[T](fromF: String => T): ConfigConvert[T] = new ConfigConvert[T] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could make sense to provide helper methods like this one for each of the ConfigValueType
available to help creating ConfigConvert
s that work only with one of the value types. For String
it makes sense to render the parsed String
from the ConfigValue
and then try to parse it while for the other value types it could make sense to just return error if the type doesn't match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this in theory, but there are some specifics I'm not sure about:
- For
ConfigValueType.LIST
, should the interface require a function with type signatureList[ConfigValue] => T
, orList[U] => T
, provided that there is aConfigConvert
forU
? - For
ConfigValueType.OBJECT
, should the interface require a function with type signatureConfigObject => T
? - At least for
ConfigValueType.LIST
andConfigValueType.OBJECT
, the interface should allow defining a method to render the type as aConfigValue
. Taking this into account, and considering the effort of defining aConfigConvert
, do these helpers still make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can postpone this discussion for now, this PR is big enough :-). Let's just keep this idea in consideration for future releases, I think it could be useful.
@jcazevedo I did a first full review of the code and I think it is excellent. I made a few comments but the general structure is what I was wishing for. I would like to go through the code again another day, if you don't mind and then I think we can consider to merge. Thanks for your effort! |
No problem. Thanks! I took the liberty of adding some more helper methods in this PR, so that we're able to operate directly on import pureconfig._
import com.typesafe.config._
case class Conf(a: List[Int], b: Map[String, String])
val conf = ConfigFactory.parseString("""{ "a": [1, 2, 3, 4], "b": { "k1": "v1", "k2": "v2" } }""")
// conf: com.typesafe.config.Config = Config(SimpleConfigObject({"a":[1,2,3,4],"b":{"k1":"v1","k2":"v2"}}))
conf.to[Conf]
// Success(Conf(List(1, 2, 3, 4),Map(k1 -> v1, k2 -> v2)))
conf.to[Conf].get.toConfig
// SimpleConfigObject({"a":[1,2,3,4],"b":{"k1":"v1","k2":"v2"}}) I added these in commit 306b8ee. I'm not sure if this is something you want to see in the library, so let me know if you want it removed. |
@jcazevedo I think we can merge this PR and think about releasing a new version of Before I do this, I would like to ask you a favour : commit 306b8ee adds a few implicits that, while useful, in my opinion should not be imported automatically with |
I think the @jcazevedo While we're asking for favors, please update the |
I agree that it does give more control to the developer. I've moved the implicit conversions to the
I've updated both the README and the example project. However, I had to change the configuration on the example project from |
Nice, I'll review the last changes and then we can merge. |
@jcazevedo thanks for the contribution, it's a great improvement over the previous implementation! I will publish the next artifact soon, probably labelled There is then a last thing to discuss: because you contributed so much to the library both in terms of ideas and of code, I would like to add you as author of the library. Being author means that the library is yours and you can vote on any PR and changes that will be done. We also will have soon a gitter channel where we help people and decide about the future of the library together with @leifwickland and any other brave developer that decides to contribute to pureconfig. What do you think, can I add you to the authors? |
Sure! Thanks, @melrief! |
This PR removes the
RawConfig
type, modifyingConfigConverters
to operate onConfigValue
directly.My original use case was to be able to deserialize a HOCON such as the following:
into something like the following classes:
Using
loadConfig[ListOfFoo](config)
wouldn't work, as the expected HOCON format was the following:I find that format a bit harder to read and create, and prefer the former. The conversion to
RawConfig
would make config lists to lose their types and make them harder to work with, so I decided to have a go and try to operate directly onConfigValues
. Besides enabling the original use case, I believe this has simplified some things:ConfigConvert
type class no longer has to know about namespaces, as theConfigValue
they receive already is the one they should know how to deserialize;StringConvert
andFieldConvert
classes were removed, as everything could fit into aConfigConvert
;ConfigConvert
type class is able to be derived for a traversable.I understand this is a big change, so I'm open to rework things more to your liking. I would really like for
pureconfig
to support the first use case I mentioned, though. The README and the example project should also be updated (since theStringConvert
class no longer exists), but I'd rather do that once we settle on the implementation.