这不是那很难为生成的类型编写ToJSON/FromJSON实例,但仍然可以在生成代码时将它抛入?或者是否有一种简单的方法可以让Yesod用户成为这种用户? (我没有挖过深成TH是如何工作的?)为什么Yesod中的ToJSON/FromJSON的Persistent类型实例不是?
更新: OK,我喜欢这个建议,但是,说我的执着类型是用户。如果我使用
它产生
Exception when trying to run compile-time code:
Data.Aeson.TH.withType: Unsupported type: TySynD Model.User [] (AppT (ConT Model.UserGeneric) (ConT Database.Persist.GenericSql.Raw.SqlPersist))
Code: deriveJSON (id) 'User
显然是因为它是一个别名。但
$(deriveJSON id ''UserGeneric)
产生
Kind mis-match
The first argument of `UserGeneric' should have kind `(* -> *)
-> *
-> *',
but `backend[i5XB]' has kind `*'
我可能还是得到了错误的类型,但我无法找到足够的什么持续产生,以获得正确的咒语。
你想通了吗?在这里遇到完全相同的问题。 – 2013-09-03 01:45:00
我现在还没有和Yesod一起工作过很长一段时间,但我确信我使用Michael Snoyman链接中提到的添加的“json”工作:https:// github。com/yesodweb/yesod/wiki/Persistent-entity-syntax#json-instances – svachalek 2013-09-03 05:55:08
谢谢,它的工作原理:) – 2013-09-04 00:09:51