by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Lloyd
    @lloydmeta
    can you elaborate? what would be an instance ofan enum?
    like a type alias?
    Dermot Haughey
    @hderms
    I guess you could say it would be multiple entryName mapping to the same Enum
    Lloyd
    @lloydmeta
    ah, no sorry that is not supported atm.
    Ben Stewart
    @bastewart
    Hi! Sorry to be a needy end-user but would it be possible to release a version of enumeratum-circe which depends on Circe 0.12.1? I think everything is merged so it could be released. Thank you!
    Lloyd
    @lloydmeta
    It could be, but AFAIK 0.12.1 is source-and-binary compatible with 0.12, so you could just add a dependency on that version of Circe instead and sbt/maven/ivy should pick the latest version and "just work"? unless if I'm missing something.
    Travis Brown
    @travisbrown
    @lloydmeta I’m not at a computer at the moment, but iirc the latest enumerating-circe release depends on a circe 0.12 milestone that isn’t 100% bincompat with the 0.12.x final series.
    It should work fine, given that the breakage between the milestone and 0.12.0/1 is small and unlikely to be used by enumeration-circe, but that’s not guaranteed by MiMa.
    Lloyd
    @lloydmeta
    aah, thanks for pointing that out (circe-version lagging in enumeratum-circe and no mima guarantee). will cut + publish a new version.
    Ben Stewart
    @bastewart
    Thank you!
    Dermot Haughey
    @hderms
    guessing there's no way to have a 'catch all' enum
    like if none of the other ones match we get that one
    i'm guessing i should just write a matching function and not depend on withName
    or like withNameOption and then provide a default value
    it would be convenient if this existed so that circe would automagically do this for me
    Dermot Haughey
    @hderms
    seems undesirable actually so I think I answered my own question as making it easy to create encoders/decoders that throw away information seems contrary to the design of both libraries
    Gregg Hernandez
    @gregghz
    Is it possible to create an EnumEntry that supports multiple String names such that Thing.withName("hello") and Thing.withName("hi") would both return the same entry?
    I can override the namesToValuesMap adding the additional names I think, is there any other way?
    Gregg Hernandez
    @gregghz
    Mainly I'd like another way because overriding that requires redefining the whole map (can't reference super.namesToValuesMap).
    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