Class: Hanami::Middleware::BodyParser::JsonParser Private

Inherits:
Parser
  • Object
show all
Defined in:
lib/hanami/middleware/body_parser/json_parser.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 1.3.0

Constant Summary

Constants inherited from Parser

Parser::DEFAULT_MIME_TYPES

Instance Attribute Summary

Attributes inherited from Parser

#mime_types

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#initialize

Constructor Details

This class inherits a constructor from Hanami::Middleware::BodyParser::Parser

Class Method Details

.mime_typesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.3.0



14
15
16
# File 'lib/hanami/middleware/body_parser/json_parser.rb', line 14

def self.mime_types
  ["application/json", "application/vnd.api+json"]
end

Instance Method Details

#parse(body) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse a json string

Parameters:

  • body (String)

    a json string

Returns:

  • (Hash)

    the parsed json

Raises:

Since:

  • 1.3.0



28
29
30
31
32
# File 'lib/hanami/middleware/body_parser/json_parser.rb', line 28

def parse(body, *)
  JSON.parse(body)
rescue StandardError => exception
  raise BodyParsingError.new(exception.message)
end