オブジェクトの配列を持つ json を受け入れることができる yesod ハンドラーがあります。すべてのオブジェクトをデータベースに挿入したいと思います。
newtype NodeList = NodeList [Node]
instance FromJSON NodeList where
parseJSON (Object o) = NodeList <$> o .: "nodes"
parseJSON _ = mzero
postMoreNodesR :: Handler ()
postMoreNodesR = do
nodes::NodeList <- requireJsonBody
runDB $ mapM_ insert nodes
return ()
しかし、どういうわけか、私のエンティティタイプを認識していません。(ただし、同じモジュール内の他の POST および GET ハンドラーは問題なく動作します。) かなり近いことはわかりますが、「a0」はどこにも宣言した型ではないため、どうすればよいかわかりません。エラーは次のとおりです。
Handler/Node.hs:46:30:
Couldn't match expected type `[a0]' with actual type `NodeList'
In the second argument of `mapM_', namely `nodes'
In the second argument of `($)', namely `mapM_ insert nodes'
In a stmt of a 'do' block: runDB $ mapM_ insert nodes