Marten::DB::Field::JSON
Inherits Marten::DB::Field::Base / Reference / Object
Represent's a JSON field.
JSON model fields allow to automatically parse JSON columns and expose the corresponding JSON::Any object,
which is the default behavior:
class MyModel < Marten::Model
# Other fields...
field :metadata, :json
end
It should be noted that it is also possible to specify a serializable option in order to specify a class that
makes use of JSON::Serializable. When doing so, the parsing of the JSON values will result in the
initialization of the corresponding serializable objects:
class MySerializable
include JSON::Serializable
property a : Int32 | Nil
property b : String | Nil
end
class MyModel < Marten::Model
# Other fields...
field :metadata, :json, serializable: MySerializable
end
Constructors
new(id : ::String, primary_key = false, default : ::JSON::Any | ::JSON::Serializable | Nil = nil, blank = false, null = false, unique = false, index = false, db_column = nil, **kwargs)
SourceInstance methods
Extracts the field value from a DB result set and returns the right object corresponding to this value.