class Karafka::Parsers::Json
Default Karafka Json parser for serializing and deserializing data
def self.generate(content)
- Example: From a string (no changes) -
Example: From an ActiveRecord object -
Other tags:
- Note: - When string is passed to this method, we assume that it is already a json
Raises:
-
(Karafka::Errors::ParserError)- raised when we don't have a way to parse
Returns:
-
(String)- Valid JSON string containing serialized data
Parameters:
-
content(Object) -- any object that we want to convert to a json string
def self.generate(content) return content if content.is_a?(String) return content.to_json if content.respond_to?(:to_json) raise Karafka::Errors::ParserError, content end
def self.parse(content)
-
(Hash)- hash with parsed JSON data
Parameters:
-
content(String) -- content based on which we want to get our hash
def self.parse(content) ::MultiJson.load(content) rescue ::MultiJson::ParseError => e raise ::Karafka::Errors::ParserError, e end