How to write a Scala Argonaut codec for all Java enums -


i have scala project uses bunch of java code, example java source:

public enum category { foo, bar }; 

i have bunch of scala case classes serialise , json using argonaut this:

case class thing (a: string, b: int, c: float) object thing {   implicit val j = casecodec3 (thing.apply, thing.unapply)("a", "b", "c")   implicit val e: equal[guild] = equal.equal (_ == _) } 

fine, want write scala case class uses java enum so:

case class thing (a: string, b: int, c: float, d: category) object thing {   implicit val j = casecodec4 (thing.apply, thing.unapply)("a", "b", "c", "d")   implicit val e: equal[guild] = equal.equal (_ == _) } 

this yield compilation error because there no implicit codec category enum.

i guess write own codec dealing category enum doing this:

package object argonautimplicits {   implicit val dx: decodejson[category] = stringdecodejson.map(x => category.valueof(x))   implicit val ex: encodejson[category] = encodejson(x => jstring(x.tostring)) } 

but want know if there way write single codec automatically handle java enum.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -