Module: Puma::JSONSerialization

Defined in:
lib/puma/json_serialization.rb

Overview

Puma deliberately avoids the use of the json gem and instead performs JSON serialization without any external dependencies. In a puma cluster, loading any gem into the puma master process means that operators cannot use a phased restart to upgrade their application if the new version of that application uses a different version of that gem. The json gem in particular is additionally problematic because it leverages native extensions. If the puma master process relies on a gem with native extensions and operators remove gems from disk related to old releases, subsequent phased restarts can fail.

The implementation of JSON serialization in this module is not designed to be particularly full-featured or fast. It just has to handle the few places where Puma relies on JSON serialization internally.

Defined Under Namespace

Classes: SerializationError

Constant Summary collapse

QUOTE =
/"/
BACKSLASH =
/\\/
CONTROL_CHAR_TO_ESCAPE =

As required by ECMA-404

/[\x00-\x1F]/
CHAR_TO_ESCAPE =
Regexp.union QUOTE, BACKSLASH, CONTROL_CHAR_TO_ESCAPE

Class Method Summary collapse

Class Method Details

.generate(value) ⇒ Object



29
30
31
32
33
34
# File 'lib/puma/json_serialization.rb', line 29

def generate(value)
  StringIO.open do |io|
    serialize_value io, value
    io.string
  end
end