Я изучаю Argonaut и могу декодировать json вручную:
foo = """{"f":"xxx"}"""
newtype Foo =
Foo {
f :: String
}
derive instance genericFoo :: Generic Foo
instance decodeJsonFoo :: DecodeJson Foo where
decodeJson json = do
obj <- decodeJson json
f <- obj .? "f"
pure $ Foo { f }
main = either log (\x -> log $ show $ decodeJson x :: Either String Foo) (jsonParser foo)
Вместо этого я пытаюсь использовать дженерики, и я подумал
instance decodeJsonFoo :: DecodeJson Foo where
decodeJson = gDecodeJson
должно сработать.
однако я получил (Left "When decoding a Main.Foo: 'tag' property is missing")
просмотрел Generic. purs, но я новичок в дженериках и не могу понять.
Я что-то не понимаю или как это исправить?