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

Prototype JSON::Coder #718

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

etiennebarrie
Copy link
Contributor

This is still a WIP.

This API allows to use strict mode while defining how to serialize custom objects in a non-global way (without defining to_json on the objects' classes).
It translates into another primitive object supported by JSON and leaves the serialization to the JSON gem.

@paddor
Copy link

paddor commented Dec 22, 2024

I love this. That's exactly what I'd need to make sure my Time objects are encoded as ISO8601 with millisecond precision without monkey patching.

Doing this just doesn't feel right:

class Time
  def to_json(*a)
    iso8601(3).to_json(*a)
  end
end

So far I've been relying on Oj's time_format: :xmlschema, second_precision: 3.

byroot added a commit to byroot/json that referenced this pull request Jan 13, 2025
Ref: ruby#718

The existing `Parser` interface is pretty bad, as it forces to
instantiate a new instance for each document.

Instead it's preferable to only take the config and do all the
initialization needed, and then keep the parsing state on the
stack on in ephemeral memory.

This refactor makes the `JSON::Coder` pull request much easier to
implement in a performant way.

Co-Authored-By: Étienne Barrié <[email protected]>
byroot added a commit to byroot/json that referenced this pull request Jan 13, 2025
Ref: ruby#718

The existing `Parser` interface is pretty bad, as it forces to
instantiate a new instance for each document.

Instead it's preferable to only take the config and do all the
initialization needed, and then keep the parsing state on the
stack on in ephemeral memory.

This refactor makes the `JSON::Coder` pull request much easier to
implement in a performant way.

Co-Authored-By: Étienne Barrié <[email protected]>
Co-authored-by: Jean Boussier <[email protected]>
hsbt pushed a commit to hsbt/ruby that referenced this pull request Jan 14, 2025
…sing state

Ref: ruby/json#718

The existing `Parser` interface is pretty bad, as it forces to
instantiate a new instance for each document.

Instead it's preferable to only take the config and do all the
initialization needed, and then keep the parsing state on the
stack on in ephemeral memory.

This refactor makes the `JSON::Coder` pull request much easier to
implement in a performant way.

ruby/json@c8d5236a92

Co-Authored-By: Étienne Barrié <[email protected]>
hsbt pushed a commit to hsbt/ruby that referenced this pull request Jan 14, 2025
…sing state

Ref: ruby/json#718

The existing `Parser` interface is pretty bad, as it forces to
instantiate a new instance for each document.

Instead it's preferable to only take the config and do all the
initialization needed, and then keep the parsing state on the
stack on in ephemeral memory.

This refactor makes the `JSON::Coder` pull request much easier to
implement in a performant way.

ruby/json@c8d5236a92

Co-Authored-By: Étienne Barrié <[email protected]>
byroot added a commit to ruby/ruby that referenced this pull request Jan 14, 2025
…sing state

Ref: ruby/json#718

The existing `Parser` interface is pretty bad, as it forces to
instantiate a new instance for each document.

Instead it's preferable to only take the config and do all the
initialization needed, and then keep the parsing state on the
stack on in ephemeral memory.

This refactor makes the `JSON::Coder` pull request much easier to
implement in a performant way.

ruby/json@c8d5236a92

Co-Authored-By: Étienne Barrié <[email protected]>
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