Giter VIP home page Giter VIP logo

Comments (4)

grzegorz-bielski avatar grzegorz-bielski commented on September 25, 2024 1

Hello @nemoo!

There are two issues here.

First, you need to actually trigger the derivation for ServiceConf and AuthMethod. There is no auto derivation in Scala 3.
With the derivation from pureconfig-core it could be done as:

case class ServiceConf(
  host: String,
  port: Port,
  useHttps: Boolean,
  authMethods: List[AuthMethod]
) derives ConfigReader

or

given ConfigReader[ServiceConf] = ConfigReader.derived[ServiceConf]

You should do the same for AuthMethod.

Second problem is that currently PureConfig doesn't support value class derivation in Scala 3, but you can define your own instance like this:

given ConfigReader[Port] = ConfigReader.fromStringTry(str => scala.util.Try(str.toInt)).map(Port.apply)

from pureconfig.

grzegorz-bielski avatar grzegorz-bielski commented on September 25, 2024 1

@rladstaetter Thanks!

As you know, the derivation for Scala 3 ConfigWriters is not yet merged.

In the meantime you can create your own writers manually through combination of factory methods on ConfigWriter and ConfigValueFactory like this:

import pureconfig.*
import com.typesafe.config.{ConfigValue, ConfigValueFactory}
import scala.jdk.CollectionConverters.*

case class Foo(bar: String, baz: Int)

given fooWriter: ConfigWriter[Foo] = ConfigWriter.fromFunction: foo => 
  ConfigValueFactory.fromMap(
    Map(
      "bar" -> foo.bar,
      "baz" -> foo.baz
    ).asJava
  )

println(
  fooWriter.to(Foo(bar = "bar", baz = 1)).render()
)

from pureconfig.

nemoo avatar nemoo commented on September 25, 2024 1

@grzegorz-bielski thanks a lot, that works fine! Will definitely check back in on pureconfig once full scala 3 support has landed.

Some impressions: I found the documentation hard to digest for newcomers, especially to get started quickly. As an inspiration: I find lihaoyi documentations like this one https://github.com/com-lihaoyi/requests-scala great because they offer ready to use relevant use case examples right on the main README.

from pureconfig.

rladstaetter avatar rladstaetter commented on September 25, 2024

Thanks @grzegorz-bielski for this, and also your work and time you are investing in this great library recently.

I'm trying to use pureconfig in my project with scala3, but unfortunately I didn't yet find out how to create ConfigWriters. Can you provide an example for those classes mentioned above as well?

I would be happy to create them manually without derivation, but I'm lost and unsure what is the way to go.

from pureconfig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.