Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Freddie Sanchez
    @FreddieSanchez
    Hello
    I want to separate out the circe & argonaut decoding/decoding to a separate sub module of my library. How would I go about doing this?
    basically, I don't want my object to extend with CirceEnum[A] in the main implementation
    Gregg Hernandez
    @gregghz
    have your module with an object that extends CirceEnum[A], then import that object's members where you need the implicits
    Freddie Sanchez
    @FreddieSanchez
    I'd like to avoid any dependencies (like circe) in the main module.
    and only have circe in the circe submodule
    Gregg Hernandez
    @gregghz
    ok so put that object in the submodule. Then .... do what with it? If it's a library for users, just document how to use it with imports
    Freddie Sanchez
    @FreddieSanchez
    I just want the plain enum in the main module, then all the circe dependencies in the circe submodule that includes the main module. That currently can't be done, as I see it since extending CirceEnum[A] is not allowed to non-abstract or non-sealed traits
    Gregg Hernandez
    @gregghz
    you can just create an object in your submodule that implements the encoder/decoder:
    object circe {
      implicit val encoder = enumeratum.Circe.encoder(TargetEnumObject)
      implicit val decoder = enumeratum.Circe.decoder(TargetEnumObject)
    }
    that's all CirceEnum does, except it requires being attached to the enum, like you say
    check out Circe.scala in the enumeratum project for more methods you could use, and CirceEnum.scala to see how CirceEnum[A] works
    Freddie Sanchez
    @FreddieSanchez
    That seems to work
    Thank you
    But can you not ShirtSize.Medium.asJson ?
    I can do ShirtSize.withName("Medium").asJson
    Gregg Hernandez
    @gregghz
    the first should work
    Freddie Sanchez
    @FreddieSanchez
    I'm getting the infamous error, can't find implicit for Encoder[ShirtSize.Medium.type]
    Gregg Hernandez
    @gregghz
    ah, bummer. not sure of a good fix. .asJson(Encoder[ShirtSize]) might work
    Paulius Imbrasas
    @CremboC
    Hey, thanks for the library. I have a smaller issue, however, which seems to contradict the "reflection-free" title. I am trying to build an native image using Graal of an app that uses enumeratum, but it keeps failing due to usage of scala.reflect. It seems that Enumeratum is one of two libraries that uses scala.reflect meaning I can't build an image. Anyone has tried this before?
    davidnadeau
    @davidnadeau
    My json receives values in uppercase and lowercase sometimes.
    I can only get it working with circeenum with 1 or the other. Is there a way to make it work with both?
    sealed trait Currency extends EnumEntry with Lowercase
    
    object Currency extends Enum[Currency] with CirceEnum[Currency] {
      val values = findValues
    
      case object JPY extends Currency
      case object CAD extends Currency
    }
    this only does lowercase: "cad", "jpy". and using with Uppercase only does uppercase. Mixing them both together just works with whichever was mixed in last.
    davidnadeau
    @davidnadeau

    i made:

    trait CirceCaseInsensitiveEnum[A <: EnumEntry] { this: Enum[A] =>
      implicit val circeEncoder: Encoder[A] = Circe.encoder(this)
      implicit val circeDecoder: Decoder[A] = Circe.decodeCaseInsensitive(this)
    }

    works now

    Lloyd
    @lloydmeta
    Yeah, I think that's how I would do it at the moment :)
    davidnadeau
    @davidnadeau
    pretty awesome that all those methods exist on the Circe object, thank you.
    Mikhail Nemenko
    @eniqen
    Hi is there any chance to have fallback in enumeratur circe ?
    Igor Tovstopyat-Nelip
    @igortn

    I am trying to write a polymorphic function that would return an optional enum entry. Something along these lines:

    def f[T <: Enum[_]](s: String): Option[T] = T.withNameOption(s)

    And, the above will not work. Anybody has an idea how this should be done correctly?

    Igor Tovstopyat-Nelip
    @igortn
    Ok, found the solution:
    def f[T <: EnumEntry: Enum](s: String) = implicitly[Enum[T].withNameOption[T]
    Matt Dziuban
    @mrdziuban
    would a pull request be accepted to include objects defined inside objects in the companion object? e.g.
    sealed trait Thing extends EnumEntry
    
    object Thing extends Enum[Thing] {
      case object Foo extends Thing
    
      object other {
        // not currently included in values
        case object Bar extends Thing
      }
    }
    Ender Tunc
    @endertunc_gitlab

    Hey all, I have a quick question.
    I am passing enum to doobie and it does not seem to be using entryName.
    I have the following:

        println(s"ENUM: ${enum.entryName}")
        val fragment: Fragment = fr"........ ORDER BY $enum"

    I expect LowerCamelcase and println works as expected but value passed to doobie does not. Am I doing something wrong here?

    volgad
    @volgad

    Hi All, I have a question regarding using Enumeratum. I have used it for a while and thought it was really a usefull add on to scala. I have an akka stream system that I am moving to akka cluster. In order to pass messages, I use Jackson and I found very hard to make the EnumEntry serializable. The reasons being

    1) th enecessity to pass a made up Type for the the enum entries in the following (because it needs to be a class not a type like object)
    @JsonSubTypes(
    Array(new JsonSubTypes.Type(value =

    2) The reverse serialization of the object with

    @JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    property = "type",

    visible = true
    )

    I also tried to use implicit val formats: Formats = DefaultFormats + Json4s.serializer() as suggested on git enumeratum

    I eventually made it work by turing my case object into a final case class. Does anybody have a pointer or reference / example oin how to make this work? Thank you
    vonchav
    @voonchav_gitlab
    Hi all, the core enumeratum (as well as the circe module) has been updated to 1.6.1. The enumeratum-quill module remains at 1.6.0. Does it need to be upgraded to 1.6.1 too? Or is the point version bump not relevant to the enumeratum-quill module? I use one version variable in sbt for all my enumeratum modules . Just wondering.
    Diego E. Alonso Blas
    @diesalbla
    @lloydmeta Similar to the question above: are now all packages of enumeratum to be kept and released on same version numbers, going on?
    Adrian
    @adrian-salajan

    Hi, i would like to have encoder for something like this:

    sealed trait MainType
    class MainA extends MainType
    class MainB extends MainType
    
    sealed abstract class Subtypee[_ <: MainType](override val entryName: String) extends EnumEntry
    
    object Subtypee extends Enum[Subtypee[_]] with CirceEnum[Subtypee[_]] {
    
      def values = findValues
    
      case object A1 extends Subtypee[MainA]("A1")
      case object A2 extends Subtypee[MainA]("A2")
    
      case object B1 extends Subtypee[MainB]("B1")
      case object B2 extends Subtypee[MainB]("B2")
    }
    
    import io.circe.syntax._
    import io.circe._
    import io.circe.Json
    import io.circe.generic.semiauto._
    
    println(">>>>>>>>>>>>>" + Subtypee.A1.asJson)

    but i get

     could not find implicit value for parameter encoder: io.circe.Encoder[com.ing.raptor.generic.cloudEvents.mom.Subtypee.A1.type]
    Adrian
    @adrian-salajan
    ^i redesigned having one separate enum for each subtype
    Gavin Bisesi
    @Daenyth

    :wave: I'm wondering if I can make an inductive implicit for any Enum?

    I have an implicit def stuff[E <: EnumEntry]: otherLib.FromStringStuff[E] = str => Enum.materializeEnum[E].withName(str)
    But the macro fails with Could not find the companion object for type type E.

    I also tried giving it a ClassTag implicit in case that would help satisfy the WeakTypeTag, but it still fails
    Gavin Bisesi
    @Daenyth
    :eyes: Actually, is there a reason Enum doesn't provide implicit val fooEnum: Enum[A] = this onto the companion?
    ah I think it worked when I changed it to implicit def stuff[E <: EnumEntry: Enum]...
    that probably got the materialize macro into the right location to have a fixed name to search for
    Diego E. Alonso Blas
    @diesalbla
    Good morning !
    We are curious: what are the plans for the enumeratum library re: Scala 3, a.k.a. dotty?
    The Dotty docs refer to an apparently easier syntax for enum values in http://dotty.epfl.ch/docs/reference/enums/enums.html,
    but I am not sure if the problems addressed by enumeratum are fixed in there...
    Also, I understand that enumeratum depends on some macro code as well, to generated the methods. Is there a plan to port that to the new MetaProgramming of Scala 3?
    Gavin Bisesi
    @Daenyth
    Can't speak for the enumeratum devs, but I believe most of what enumeratum addresses won't be a problem in scala3 enums.
    Diego E. Alonso Blas
    @diesalbla
    Well, I was asking two different questions:
    1) Could enumeratum become no longer needed, because Scala 3 enums provide those features?
    2) Would there be a problem to re-implement enumeratum macro code on Scala 3?
    Luís Campos
    @LLCampos
    @lloydmeta, following up from the above: what are the plans regarding Scala 3? :)
    Lloyd
    @lloydmeta

    Good question.. from what I've seen of the Scala 3 enums, I think it might not be necessary to implement the core macro in Scala 3.

    I haven't taken a look lately, but IIRC the whole metaprogramming toolkit has been completely revamped in Scala 3, so while possible to port the macro in some form, it would be a substantial rework.

    If anything, I would want to see what kind of needs (complaints :D) people have with Scala 3 enums before trying to fit enumeratum into Scala 3.

    Gavin Bisesi
    @Daenyth
    For me the main thing would be - if we can hit source compatibility between the scala2 and scala3 bases, or even just mostly source compatibility, that's all I care about
    I just want to be able to cross-publish when the time comes
    George Westwater
    @westwater

    @lloydmeta Similar to the question above: are now all packages of enumeratum to be kept and released on same version numbers, going on?

    Would love to get an answer to this, some of the extension modules are out by a patch version

    Henri Cook
    @henricook
    Hi all, I was just looking for release notes between 1.6.1 and 1.6.2 - do they get published somewhere?