Giter Club home page Giter Club logo

Comments (7)

lloydmeta avatar lloydmeta commented on July 17, 2024 3

I think case objects already extend Serializable by default, so the problem might be as you said; the lack of a no-args constructor on the parent.

Perhaps something like this could work?

sealed trait PhBoardingStatus extends EnumEntry

object PhBoardingStatus extends Enum[PhBoardingStatus] {

  val values = findValues

  case object All       extends PhBoardingStatus { override val entryName = "ALL"}
  case object Closed    extends PhBoardingStatus { override val entryName = "BC" }
  case object Ignored   extends PhBoardingStatus { override val entryName = "BI" }
  case object NotOpen   extends PhBoardingStatus { override val entryName = "BN" }
  case object Open      extends PhBoardingStatus { override val entryName = "BO" }
  case object Suspended extends PhBoardingStatus { override val entryName = "BS" }
}

from enumeratum.

tsabran avatar tsabran commented on July 17, 2024 3

I've added this in the sealed abstract class instead, which I find less verbose and seems to work fine too:

    def this() = this("")

Yet I'm not familiar enough with this to understand why we need this no-param constructor and if it could be fixed directly in the EnumEntry...

from enumeratum.

DonDebonair avatar DonDebonair commented on July 17, 2024 1

I'm gonna try this and will let you know if it works. Thanks for the tip!

from enumeratum.

antonkulaga avatar antonkulaga commented on July 17, 2024 1

I also had such problem. I think it must be fixed because it mays API very verbose

from enumeratum.

mt40 avatar mt40 commented on July 17, 2024 1

@lloydmeta your solution works but it leave the code more verbose unnecessarily. Is there a better fix for this situation?

from enumeratum.

lloydmeta avatar lloydmeta commented on July 17, 2024 1

The problem is the lack of a no-arg constructor, which is required for Java Serialisation to work.

If you don't need to customise the entryName, then a simple argument-free abstract class extending EnumEntry might work too.

@kantlove @antonkulaga if you have other ideas, send PRs.

from enumeratum.

achelimed avatar achelimed commented on July 17, 2024

Hi,
I had the same problem but with my enum extending enumeratum.EnumEntry.Lowercase trait. I think that the problem is the same because Lowercase trait overrides the entryName too.
I have chosen the def this() = this("") option to resolve the problem because it is less verbose.
Thanks @tsabran

from enumeratum.

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.