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

Open up the coercion stack #224

Merged
merged 2 commits into from
Feb 5, 2020
Merged

Open up the coercion stack #224

merged 2 commits into from
Feb 5, 2020

Conversation

cddr
Copy link
Contributor

@cddr cddr commented Jan 30, 2020

A few people have noticed that the JSON representation of an avro object is a bit different to the edn representation of an avro object. This behaviour was originally copied from the abracad.avro project but it makes it a little bit inconvenient to work with data obtained via more "avro-oriented" tools like the kafka-avro-console-consumer or the avro-random-generator.

The pair of functions in this PR make it a bit easier to convert between these two representations.

Example Usage

as-json

(as-json {:avro-schema (clojure.data.json/write-str ["null" "string"])}
          "yolo")
=> "{\"string\":\"yolo\"}"

as-edn

(as-edn {:avro-schema (clojure.data.json/write-str ["null" "string"])}
        "{\"string\":\"yolo\"}")
=> "yolo"

Checklist

  • factor out the common code that builds the coercion-stack
  • tests
  • updated CHANGELOG (the "unreleased" section)

@cddr cddr requested a review from a team as a code owner January 30, 2020 15:27
@codecov
Copy link

codecov bot commented Jan 30, 2020

Codecov Report

Merging #224 into master will decrease coverage by 0.22%.
The diff coverage is 96.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #224      +/-   ##
==========================================
- Coverage   79.97%   79.74%   -0.23%     
==========================================
  Files          42       42              
  Lines        2597     2622      +25     
  Branches      150      151       +1     
==========================================
+ Hits         2077     2091      +14     
- Misses        370      380      +10     
- Partials      150      151       +1
Impacted Files Coverage Δ
src/jackdaw/serdes/avro.clj 88.5% <96.96%> (+0.58%) ⬆️
src/jackdaw/serdes/edn2.clj 45.45% <0%> (-45.46%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6a58fb...452eeff. Read the comment docs.

@cddr cddr changed the title [RFC] Open up the coercion stack Open up the coercion stack Feb 4, 2020
:type-registry (merge avro/+base-schema-type-registry+
avro/+UUID-type-registry+)}
valid-edn)
(json/read-str))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you add a keywordize-keys here (or probably pass an option to json/read-string) you can avoid all the get below and just use the usual keyword syntax.

@AndreaCrotti AndreaCrotti self-requested a review February 4, 2020 11:29
@AndreaCrotti
Copy link
Contributor

No tests yet.

You can remove that from the description of the PR since you added them

Copy link
Contributor

@AndreaCrotti AndreaCrotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cddr cddr merged commit 9bbf58b into master Feb 5, 2020
@cddr cddr deleted the coercion-stuff branch February 5, 2020 10:58
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

Successfully merging this pull request may close these issues.

2 participants