purescript-contrib/purescript-argonaut-generic

unwrapSingleArguments should create an object and not a mix of object and array

Closed this issue · 2 comments

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

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.

I believe this is intended behavior, at least for the reasons you mentioned. Thanks for bringing this up, though!