genericEncodeJson not respecting `EncodeJson` instances of fields
Closed this issue · 2 comments
I hope the example clarifies:
data Foo = Foo Bar
data Bar = Bar
derive instance genericFoo :: Generic Foo
derive instance genericBar :: Generic Bar
instance encodeJsonFoo :: EncodeJson Foo where
encodeJson = genericEncodeJson Argonaut.options
instance encodeJsonBar :: EncodeJson Bar where
encodeJson _ = fromString "yippie"
main :: forall e. Eff (console :: CONSOLE | e) Unit
main = Console.log $ Json.stringify $ encodeJson $ Foo Bar
-- I expected "yippie" to show up in the outputI've also created a repro repo: https://github.com/felixSchl/repro-encodejson
Well, this was confusing! What you're using here is a different library - https://github.com/eskimor/purescript-argonaut-generic-codecs
I don't think it can support what you want either, a restriction of "old generics" (non-Generic.Rep) is that it uses generics all the way down. This library does have variations for new and old generics however.
Sorry for being confusing. I must have confused myself by 3 different Encode and Decode imports (sometimes Generic.Encode, then Encode.Generic etc). Anyway, I've had a catch up with one of the guys on IRC and learned about Generic.Rep. It looks awesome and will do the trick, if only I could have constructorTagModifiers for it, but that's a separate issue.