module String::RawConverter

Overview

Converter to be usedwithJSON::Serializable to read the raw value of a JSON object property as aString.

It can be useful to read ints and floatswithout losing precision, or to read an object and deserialize it later based on some condition.

require "json"

class Raw
  include JSON::Serializable

  @[JSON::Field(converter: String::RawConverter)]
  property value : String
end

raw = Raw.from_json(%({"value": 123456789876543212345678987654321}))
raw.value   # => "123456789876543212345678987654321"
raw.to_json # => %({"value":123456789876543212345678987654321})

Defined in:

json/from_json.cr
json/to_json.cr

Class Method Summary

Class Method Detail

def self.from_json(value : JSON::PullParser) : String #

def self.to_json(value : String, json : JSON::Builder) : Nil #