Comments (5)
Hi @kindaro — I'm no longer a maintainer of this library, but you may be able to find someone in the #contrib channel on Discord who can look at this with an eye to merging. However, some thoughts. First in brief, then a bit longer:
In brief, I'm OK with adding this dependency and a instance for Ratio
, although I'm always uneasy to add more dependencies to an already-large library, and I doubt that adding this instance will solve all your problems. First, because this library makes no promises to be Aeson-compatible, and second, because you will probably encounter more types you want instances for and we may not be open to adding some of them to this library. At that point you'll need a new approach anyways. Personally, I recommend forking this library to explicitly work with purescript-bridge
and aeson
.
My case specifically is related to argonaut-aeson-generic and purescript-bridge, so it is important to me that the encoding matches the Haskell side of my code.
I recommend being careful here. Argonaut does not promise to match Aeson, though it borrows heavily from that library. I don't expect that all instances in this library are the same as the Aeson forms, and they may diverge in the future. If you need to have a JSON library that exactly matches Aeson for use with purescript-bridge, then I think you should fork this library or create a new one with that explicit goal (that would also let you write any additional instances you want).
Since PureScript does not support orphan instances, I have no other way of making stuff work.
Yes, this is a problem with type class codec libraries like argonaut-codecs
. They're a convenient base but are a huge pain when you need to diverge from the "canonical" implementation they provide or you need to add instances of a class you don't own to a type you don't own. (In my applications I use codec-argonaut
for this very reason — sometimes I need more than one way to serialize a given type).
The most common thing to do is write a new app-specific class in your codebase for dealing with JSON. The Decoders and Encoders modules exist to help you write your own classes by providing default implementations:
https://github.com/purescript-contrib/purescript-argonaut-codecs/blob/main/src/Data/Argonaut/Decode/Decoders.purs
https://github.com/purescript-contrib/purescript-argonaut-codecs/blob/main/src/Data/Argonaut/Encode/Encoders.purs
You can copy/paste the Argonaut classes into your application:
https://github.com/purescript-contrib/purescript-argonaut-codecs/blob/main/src/Data/Argonaut/Decode/Class.purs
https://github.com/purescript-contrib/purescript-argonaut-codecs/blob/main/src/Data/Argonaut/Encode/Class.purs
and either use the Decoders and Encoders modules as the implementation, adding any more instances you want, or you can skip the dependency on argonaut-codecs altogether and just copy the relevant implementations you want into your codebase.
There are other, worse options: for example, you can newtype Ratio
, and then write an instance for your newtype.
There was a bit of discussion on the discord about this, and the point was brought up that adding dependencies on js libraries is something that might want to be avoided for this library. My 2p: it's probably fine, since argonaut-core is very tied to JS anyway.
That's a good point; with purescript-json
available, if we won't be switching to it instead of purescript-argonaut-core
in this library, then maybe Argonaut just accepts that it is tied to the JS backend and JS dependencies don't matter.
from purescript-argonaut-codecs.
There was a bit of discussion on the discord about this, and the point was brought up that adding dependencies on js libraries is something that might want to be avoided for this library.
My 2p: it's probably fine, since argonaut-core
is very tied to JS anyway. purescript-json
is intended to replace it - it's heavily based on argonaut, but choices have been made to make it more reasonable for other backends to implement. (Also it's not published yet, but will be doing so this weekend).
from purescript-argonaut-codecs.
from purescript-argonaut-codecs.
Thank you @garyb @thomashoneyman.
I am going to be building my stuff from my own fork for now. Whether this feature gets merged or not, in the long term I shall need to talk to @eskimor (maintainer of purescript-bridge
) and @coot (maintainer of purescript-argonaut-aeson-generic
) about whether it makes sense to make an official fork that promises to be compatible with Aeson.
from purescript-argonaut-codecs.
I am no longer the maintainer of purescript-argonaut-aeson-generic
. You should speak with @peterbecich or @StephenWakely.
from purescript-argonaut-codecs.
Related Issues (20)
- Decoding into Map key value expects an array instead of an object HOT 2
- `Map String a` <-> Object HOT 1
- Recursive newtype in not deriving HOT 1
- Add `fromJson` and `toJson` HOT 3
- suggestion to replace `"value"` with `"contents"` in `Either` decoder, encoder HOT 2
- Use `elaborateFailure` in `getFieldOptional'` HOT 4
- Address breaking change in typelevel-prelude dependency for PureScript v0.13.0 HOT 1
- Instance for NonEmptyArray? HOT 2
- Feature Request: Enable the default record serialization to be customized HOT 1
- Add instances for 'unordered-collections' data types HOT 2
- Deprecate .:? (getFieldOptional) and .!= (defaultField) HOT 5
- why is `L.insertAt 0 h t` is used? HOT 3
- Implement typed errors HOT 3
- move JsonDecodeError type to separate package HOT 5
- Wrong type shown in docs HOT 1
- add decoder for NonEmptyString HOT 2
- Support decoding of undefined record field to Nothing HOT 1
- Encode/Decode Natural HOT 1
- An instance for nested tuples?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-argonaut-codecs.