我正在尝试使用selectRep
Yesod 1.2 中的新功能,但我无法让 json 响应正常工作。
instance ToJSON (Entity Feed) where
toJSON (Entity uid (Feed url lastUpdated)) = object
[ "id" .= uid
, "url" .= url
, "lastUpdated" .= lastUpdated
]
getFeedByIdR :: FeedId -> Handler TypedContent
getFeedByIdR feedId = do
feed <- runDB $ get404 feedId
selectRep $ do
provideRep $ return $ toJSON (Entity feedId feed)
我从上面的代码中得到的错误是
Handler/Feed.hs:23:31:
Overlapping instances for ToJSON (Entity Feed)
arising from a use of `toJSON'
Matching instances:
instance ToJSON e => ToJSON (Entity e)
-- Defined in `persistent-1.2.0.1:Database.Persist.Class.PersistEntity'
instance ToJSON (Entity Feed) -- Defined at Handler/Feed.hs:5:10
In the second argument of `($)', namely
`toJSON (Entity feedId feed)'
In the second argument of `($)', namely
`return $ toJSON (Entity feedId feed)'
In a stmt of a 'do' block:
provideRep $ return $ toJSON (Entity feedId feed)
似乎持久确实确实为ToJSON (Entity e)
hereToJSON (Entity Feed)
提供了一个实例,但是我可以以某种方式使用我的吗?