unwrapSingleArguments should create an object and not a mix of object and array
Closed this issue · 2 comments
andys8 commented
Environment
- PureScript [version] 0.13.8
purescript-argonaut-generic[version] 0.6.0
Current behavior
data NodeContent
= NodeContentStart
| NodeContentEnd { returnValue :: String }
encoding :: Encoding
encoding = defaultEncoding { tagKey = "tag", unwrapSingleArguments = true, valuesKey = "values" }
instance encodeJsonNodeContent :: EncodeJson NodeContent where
encodeJson = genericEncodeJsonWith encoding
instance decodeJsonNodeContent :: DecodeJson NodeContent where
decodeJson = genericDecodeJsonWith encoding
If there is an argument unwrapSingleArguments makes values and object, instead of an array objects.
If there is no argument, values will be an empty array.
Expected behavior
I'd expect an empty object if there are no arguments (for consistency).
toJsonString NodeContentStart
-- Actual: "{\"values\":[],\"tag\":\"NodeContentStart\"}"
-- Expected: "{\"values\":{}\,\"tag\":\"NodeContentStart\"}"
Code
purescript-argonaut-generic/src/Data/Argonaut/Encode/Generic/Rep.purs
Lines 52 to 53 in fbaa763
andys8 commented
Now looking at this issue from another angle: Maybe this doesn't make sense if the argument is a primitive type and not an object. Maybe it would be the best solution to leave the values field away?
Feel free to close the issue.
thomashoneyman commented
I believe this is intended behavior, at least for the reasons you mentioned. Thanks for bringing this up, though!