Navigation Menu

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

Create an abstract Any for JSON/YAML #6423

Closed
wants to merge 1 commit into from

Conversation

j8r
Copy link
Contributor

@j8r j8r commented Jul 21, 2018

Merges duplications between YAML::Any and JSON::Any to a common Any abstract struct, which is inherited.

External shards implementing configurations formats will also be able to inherit from it.

Partially related to #5155

Note: this PR is a background work to implement this POC https://gist.github.com/j8r/2820157756ce55182c85667cb0456800 in a future PR - the ability to deal with dynamic keys:

js = JSON.parse %({"a": {"b": "c"}, "e": [{"o": "p"}, 12, 2]})

p js[["a", "r"]]?  #=> nil
puts js[["e", 0, "o"]] = JSON::Any.new "test"
puts js        #=> {"a" => {"b" => "c"}, "e" => [{"o" => "test"}, 12_i64, 2_i64]}
js.delete ["e",0, "o"]
puts js        #=> {"a" => {"b" => "c"}, "e" => [{}, 12_i64, 2_i64]}

@asterite
Copy link
Member

@j8r Sorry, but these PRs should be discussed before implemented.

I personally agree with one of Go's proverb:

A little copying is better than a little dependency

Just because the code is similar, it shouldn't involve a dependency.

So a strong 👎 from me here.

@j8r
Copy link
Contributor Author

j8r commented Jul 21, 2018

Note that the API and implementations between the Anys aren't the same:
no YAML::Any#as_bool, YAML::Any#as_f32 and JSON::Any#as_bytes

In JSON::Any, there are as_i if @raw.is_a?(Int) and in YAML::Any @raw.as?(Int64).try &.to_i

@ysbaddaden
Copy link
Contributor

I think we need more analysis and experiments on (de)serialization before conducting such changes. For example I'd love some attempts at a Serde like solution (from Rust).

@j8r
Copy link
Contributor Author

j8r commented Jul 22, 2018

I'll create a shard because for now dealing with dynamic mappings isn't possible in the stdlib

@j8r j8r closed this Jul 22, 2018
@ysbaddaden
Copy link
Contributor

Yes, please experiment and return back your results, both successes and shortcomings :)

@j8r
Copy link
Contributor Author

j8r commented Aug 2, 2018

For information: a repository is created, https://github.com/j8r/dynany

@j8r j8r deleted the any_abstract_struct branch October 16, 2018 08:41
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.

None yet

3 participants