-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
easily encode/decode records #5
Comments
Perhaps we could add a special case in How does that sound? |
At the moment To be honest, I didn't really intend it to be used as something "human consumable", the primary target are the cases where you just need an isomorphic serialization/deserialization (like if you want to save something to localstorage). Making an exception for newtypes would break that property, and For example if you have: newtype Natural = Natural Int You probably don't want |
I guess I'll just write my own version of It would be nice to have a function similar to Then you would be able to write something like this:
|
I am currently working on genericEncodeJson which takes options like Haskell's aeson does. I plan to file a pull request later in the evening. Unwrapping newtype like data is currently not supported, but it should be easy to add. |
Ok, after further investigation, this modified example from @cdepillabout does not work:
Nor does it work, if you add:
or
this seems to be related to: I was not aware of this problem, ok I think I have to implement the "unwrapUnaryRecords" option. |
unwrapUnaryRecords implemented here. |
Can this be closed? It doesn't serve the use case of a type having all |
Yes, I believe this can be considered fixed with the Thanks! |
Is there a way to easily encode and decode records?
For instance, I have the following type:
I'd like to use purescript-generics for the encoding and decoding like below:
But when running the following code:
I get the following output:
{"values":[{"password":"foobar","email":"email@email.com"}],"tag":"Register"}
I was expecting the output to look like this:
{"password":"foobar","email":"email@email.com"}
I tried to change the EncodeJson instance like the following:
But that just gave me the following compiler error:
The error makes sense, but I was hoping it would be easier to define
encodeJson
for records. Is there an easy way? I don't want to have to write out something like this for every type:Maybe I've just been spoiled by
aeson
:-(The text was updated successfully, but these errors were encountered: