aeson icon indicating copy to clipboard operation
aeson copied to clipboard

Option nullaryToObject to encode/decode nullary constructors as empty objects

Open epoberezkin opened this issue 3 years ago • 2 comments

issue #925

  • [x] Generic JSON/encoding/parse
  • [x] TH JSON/encoding/parse
  • [x] with rejectUnknownFields option, non-empty objects should fail (both Generic and TH
  • [x] tests
  • [x] make parsers dependent on the option, without relaxing the default behaviour

epoberezkin avatar Jan 29 '22 17:01 epoberezkin

I've figured how to add this option to TH encoding, and added tests... For TH parsing, I suspect parseNullaryMatches should change but don't yet understand how...

cc @phadej

epoberezkin avatar Oct 05 '23 23:10 epoberezkin

@phadej I think it's mergeable, and it would be great if we could upstream it - as I wrote, you can't use the library with Swift without this option.

Parsing for nullary constructors currently accepts both empty array and an object (object must be empty if rejectUnknownFields is set), so it will parse JSON generated irrespective of this option.

epoberezkin avatar Oct 06 '23 10:10 epoberezkin