The newest version of Data.Aeson changed the way that ToJSON and FromJSON work for simple types like:
data Permission = Read | Write
It used to be that the generic call:
instance ToJSON Permission where
...Would create JSON that looked like {"Read":[]} or {"Write":[]}.
But now it creates:
{tag:"Read",contents:"[]"}
Which makes sense but breaks code I have written. I wrote a toJSON part by hand to give the correct looking stuff but writing the fromJSON is confusing me.
Any ideas?
Thanks
Since the value contained in the
Objectconstructor forData.Aeson.Valueis just a strictHashMap, we can extract the keys from it and make a decision based on that. I tried this and it worked pretty well.You can test it with
decode "{\"Read\": []}" :: Maybe Permission. ThemzeroinparseJSONensures that if something else is passed in, it'll just returnNothing. Since you seem to want to only check if there is a single key matching one of your two permissions, this is pretty straightforward and will properly returnNothingon all other inputs.