Skip to content
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

Conversion from/to JSON AST #201

Closed
vigoo opened this issue Mar 8, 2021 · 2 comments
Closed

Conversion from/to JSON AST #201

vigoo opened this issue Mar 8, 2021 · 2 comments

Comments

@vigoo
Copy link
Contributor

vigoo commented Mar 8, 2021

Converting the business objects to/from JSON AST is currently not supported due to the design of the library. Still this is something that would be useful in some cases.

My primary motivation is to be able to reuse an existing YAML implementation such as SnakeYAML to provide yaml support on top of zio-json. Other use cases could be some kind of transformation that is easier to perform on the JSON AST than the original model, etc.

I was thinking of the following implementation:

  • Adding an toJsonAST in JsonEncoder and a fromJsonAST to JsonDecoder
  • Have a default implementation for these which does a roundtrip serialization through a memory buffer
  • Provide overrides for the primitive types doing the conversion directly
  • Also the derive macro could generate implementations to avoid the performance loss of encoding/decoding during the conversion

Mixing this into the existing encoder and decoder type classes may seem a bit ugly but I think having it automatically available without the need to create additional implicits is a big advantage.

@fsvehla
Copy link
Contributor

fsvehla commented Mar 9, 2021

Love it.
I was having some similar—but less developed—thoughts about the AST.

Adopting the model you’ve outlined above (and carefully implementing it) allows us to reap the benefits of both approaches to JSON codecs.

@vigoo
Copy link
Contributor Author

vigoo commented Mar 13, 2021

I'll provide an initial implementation on this weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants