Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
a7dab291
Commit
a7dab291
authored
Jun 16, 2020
by
Justin Woo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle sum type nullary constructors in generic JSON
parent
15953f46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
Argonaut.purs
src/Gargantext/Utils/Argonaut.purs
+9
-0
Spec.purs
test/Gargantext/Utils/Spec.purs
+7
-0
No files found.
src/Gargantext/Utils/Argonaut.purs
View file @
a7dab291
...
...
@@ -56,6 +56,11 @@ instance genericSumDecodeJsonRepConstructor ::
argument <- genericSumDecodeJsonRep inner
pure $ GR.Constructor argument
instance genericSumDecodeJsonRepNoArguments ::
GenericSumDecodeJsonRep (GR.NoArguments) where
genericSumDecodeJsonRep _ = do
pure GR.NoArguments
instance genericSumDecodeJsonRepArgument ::
( Argonaut.DecodeJson a
) => GenericSumDecodeJsonRep (GR.Argument a) where
...
...
@@ -79,6 +84,10 @@ instance genericSumEncodeJsonRepConstructor ::
let argument = genericSumEncodeJsonRep inner
Argonaut.jsonSingletonObject name argument
instance genericSumEncodeJsonRepNoArguments ::
GenericSumEncodeJsonRep GR.NoArguments where
genericSumEncodeJsonRep GR.NoArguments = Argonaut.jsonNull
instance genericSumEncodeJsonRepArgument ::
( Argonaut.EncodeJson a
) => GenericSumEncodeJsonRep (GR.Argument a) where
...
...
test/Gargantext/Utils/Spec.purs
View file @
a7dab291
...
...
@@ -17,6 +17,7 @@ data Fruit
= Boat { hi :: Int }
| Gravy String
| Pork Int
| Chicken
derive instance eqFruit :: Eq Fruit
derive instance genericFruit :: Generic Fruit _
...
...
@@ -76,3 +77,9 @@ spec =
let result2' = Argonaut.decodeJson result2
Argonaut.stringify result2 `shouldEqual` """{"Gravy":"hi"}"""
result2' `shouldEqual` Right input2
let input3 = Chicken
let result3 = Argonaut.encodeJson input3
let result3' = Argonaut.decodeJson result3
Argonaut.stringify result3 `shouldEqual` """{"Chicken":null}"""
result3' `shouldEqual` Right input3
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment