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 ...@@ -5,7 +5,7 @@ module GEODE.Metadata.ArticleRecord
, relativePath , relativePath
, uid ) where , uid ) where
import Data.Aeson ((.=), ToJSON(..)) import Data.Aeson ((.=), FromJSON(..), ToJSON(..))
import Data.Aeson.KeyMap as KeyMap (fromList) import Data.Aeson.KeyMap as KeyMap (fromList)
import Data.Csv (FromField(..), FromNamedRecord(..), ToNamedRecord(..), ToField(..)) import Data.Csv (FromField(..), FromNamedRecord(..), ToNamedRecord(..), ToField(..))
import GEODE.Metadata.Record (Record(..)) import GEODE.Metadata.Record (Record(..))
...@@ -34,6 +34,8 @@ instance ToJSONObject ArticleRecord where ...@@ -34,6 +34,8 @@ instance ToJSONObject ArticleRecord where
<> "volume" .= volume <> "volume" .= volume
<> "article" .= article <> "article" .= article
instance FromJSON ArticleRecord
instance Record ArticleRecord where instance Record ArticleRecord where
uid (ArticleRecord {work, volume, article}) = uid (ArticleRecord {work, volume, article}) =
printf "%s_%d_%d" (show $ work) volume article printf "%s_%d_%d" (show $ work) volume article
......
...@@ -4,7 +4,7 @@ module GEODE.Metadata.Types ...@@ -4,7 +4,7 @@ module GEODE.Metadata.Types
, ToJSONObject(..) , ToJSONObject(..)
, type (@)(..) ) where , 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.Aeson.KeyMap as Object (union)
import Data.Csv (FromNamedRecord(..), ToNamedRecord(..)) import Data.Csv (FromNamedRecord(..), ToNamedRecord(..))
import Data.HashMap.Strict as Hash (union) import Data.HashMap.Strict as Hash (union)
...@@ -39,6 +39,5 @@ instance {-# OVERLAPPABLE #-} ToJSONObject a => ToJSON a where ...@@ -39,6 +39,5 @@ instance {-# OVERLAPPABLE #-} ToJSONObject a => ToJSON a where
toJSON = Object . toJSONObject toJSON = Object . toJSONObject
toEncoding = pairs . toJSONPairs toEncoding = pairs . toJSONPairs
instance (ToJSONObject a, ToJSONObject b) => ToJSONObject (a @ b) where instance {-# OVERLAPPABLE #-} (FromJSON a, FromJSON b) => FromJSON (a @ b) where
toJSONObject (a :@: b) = toJSONObject a `Object.union` toJSONObject b parseJSON o = (:@:) <$> parseJSON o <*> parseJSON o
toJSONPairs (a :@: b) = toJSONPairs a <> toJSONPairs b
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