Skip to content
Snippets Groups Projects
Commit fdc75cc4 authored by Alice Brenon's avatar Alice Brenon
Browse files

Add FromJSON instances for ArticleRecord and @ types

parent b7650a2a
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ module GEODE.Metadata.ArticleRecord
, relativePath
, uid ) where
import Data.Aeson ((.=), ToJSON(..))
import Data.Aeson ((.=), FromJSON(..), ToJSON(..))
import Data.Aeson.KeyMap as KeyMap (fromList)
import Data.Csv (FromField(..), FromNamedRecord(..), ToNamedRecord(..), ToField(..))
import GEODE.Metadata.Record (Record(..))
......@@ -34,6 +34,8 @@ instance ToJSONObject ArticleRecord where
<> "volume" .= volume
<> "article" .= article
instance FromJSON ArticleRecord
instance Record ArticleRecord where
uid (ArticleRecord {work, volume, article}) =
printf "%s_%d_%d" (show $ work) volume article
......
......@@ -4,7 +4,7 @@ module GEODE.Metadata.Types
, ToJSONObject(..)
, type (@)(..) ) where
import Data.Aeson (Object, Series, ToJSON(..), Value(..), pairs)
import Data.Aeson (FromJSON(..), Object, Series, ToJSON(..), Value(..), pairs)
import Data.Aeson.KeyMap as Object (union)
import Data.Csv (FromNamedRecord(..), ToNamedRecord(..))
import Data.HashMap.Strict as Hash (union)
......@@ -39,6 +39,5 @@ instance {-# OVERLAPPABLE #-} ToJSONObject a => ToJSON a where
toJSON = Object . toJSONObject
toEncoding = pairs . toJSONPairs
instance (ToJSONObject a, ToJSONObject b) => ToJSONObject (a @ b) where
toJSONObject (a :@: b) = toJSONObject a `Object.union` toJSONObject b
toJSONPairs (a :@: b) = toJSONPairs a <> toJSONPairs b
instance {-# OVERLAPPABLE #-} (FromJSON a, FromJSON b) => FromJSON (a @ b) where
parseJSON o = (:@:) <$> parseJSON o <*> parseJSON o
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment