[node] fix pubmed JSON serialization

parent 79d0ea23
...@@ -49,21 +49,17 @@ data Datafield = Gargantext ...@@ -49,21 +49,17 @@ data Datafield = Gargantext
deriving (Eq, Show, Generic) deriving (Eq, Show, Generic)
instance FromJSON Datafield where instance FromJSON Datafield where
parseJSON = withText "Datafield" $ \text -> parseJSON (String "Gargantext") = pure Gargantext
case text of parseJSON (String "Web") = pure Web
"Gargantext" parseJSON (String "Files") = pure Files
-> pure Gargantext parseJSON (Object o) = do
"Web" db <- o .: "External"
-> pure Web pure $ External db
"Files" parseJSON x = withText "Datafield" (\text ->
-> pure Files fail $ "Cannot match pattern '<db>' for string " <> T.unpack text) x
v -> case T.breakOnEnd " " v of
("External ", dbName)
-> External <$> parseJSON (String dbName)
_ -> fail $ "Cannot match patterh 'External <db>' for string " <> T.unpack v
instance ToJSON Datafield where instance ToJSON Datafield where
toJSON (External db) = toJSON $ "External " <> show db toJSON (External db) = toJSON $ object [ ("External", toJSON db) ]
toJSON s = toJSON $ show s toJSON s = toJSON $ show s
instance Arbitrary Datafield where instance Arbitrary Datafield where
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment