argonaut-shapeless icon indicating copy to clipboard operation
argonaut-shapeless copied to clipboard

Encoding `shapeless.nat._2` to `{}`?

Open kevinmeredith opened this issue 8 years ago • 3 comments

Why does _2.asJson return {} rather than JNumber(2)?

scala> import argonaut._, Argonaut._, ArgonautShapeless._; import shapeless.nat._2
import argonaut._
import Argonaut._
import ArgonautShapeless._
import shapeless.nat._2

scala> (_2).asJson
res11: argonaut.Json = {}

kevinmeredith avatar Jun 27 '17 12:06 kevinmeredith

It seems that's because shapeless.Succ is a case class, so a shapeless.Generic is found for it, with HNil as generic representation.

I guess better and higher priority codecs could be added for Nats in argonaut-shapeless.

Although the fact that Nats have a Generic is a problem too IMO... This could be addressed directly in shapeless, by preventing the Generic derivation for them.

alexarchambault avatar Jun 27 '17 13:06 alexarchambault

Would a PR for encoding and decoding Nat's be welcome in this library?

kevinmeredith avatar Jul 01 '17 17:07 kevinmeredith

@kevinmeredith Sure!

alexarchambault avatar Jul 06 '17 14:07 alexarchambault