Skip to content

Draft: #as_json should be API-ready #238

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

Closed
wants to merge 1 commit into from

Conversation

johnnyshields
Copy link
Contributor

@johnnyshields johnnyshields commented Aug 25, 2021

Work In Progress - Not Ready for Merge

#as_json should return objects for API serialization, and be different than #as_extended JSON.

The general rules for #as_json are (in order of precedence):

  1. Map directly to a native JSON type if it is possible to do so. Examples:

    • BSON::ObjectId --> JSON String
    • BSON::Int32 / Int64 --> JSON Integer
  2. Where ActiveSupport defines #as_json behavior for a Ruby object, follow the same. Examples:

    • BSON::Regexp::Raw --> Ruby Regex --> JSON String "(?-mix:dsfsd|dsf)"
    • BSON::Timestamp --> Ruby Time --> JSON String (time)
    • BSON::Decimal128 --> (similar to Ruby BigDecimal) --> JSON String "1234"
  3. For the remaining types not mentioned above, we need to decide whether we go with:

(a) alias to #as_extended_json
(b) compound object (Hash)
(c) compacted (lossy) single value representation

  • lib/bson/binary.rb --> could just return the base64, but we'd lose the type
  • lib/bson/code.rb --> can return code as string
  • lib/bson/code_with_scope.rb --> can return code as string but we'd lose the scope
  • lib/bson/db_pointer.rb --> could return just the objectId but we'd lose the ref (collection)
  • lib/bson/max_key.rb --> either { "$maxKey" => 1 } or "$maxKey"
  • lib/bson/min_key.rb --> either { "$minKey" => 1 } or "$minKey"

@johnnyshields
Copy link
Contributor Author

@alcaeus @p-mongo FYI I'm seeing this on the PR since it's my first time committing to BSON repo:

image

Since you have this protection in place, it should be find to allow Evergreen to auto-run for all contributor commits after the initial committer approval. If someone is abusive (crypto mining etc.) then you can revoke their privilege.

Let's make Evergreen auto-run for Mongoid, Mongo Ruby Driver, and BSON?

@johnnyshields johnnyshields changed the title #as_json should be API-ready Draft: #as_json should be API-ready Aug 25, 2021
@johnnyshields
Copy link
Contributor Author

Closed in favor of other PRs

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.

1 participant