I'm going to suggest that assigning an arbitrary string to a Json field should result in a validation error rather than an exception.
I have a class defined as follows:
class Mymodel
include DataMapper::Resource
property :id, Serial
property :jsonfield, Json
end
Assigning a hash or an array to jsonfield works as expected. The hash or array is properly json-ized in the data store, and when I read the field back, I get a hash/array that's identical to the original.
Assigning a string to jsonfield causes the parser to interpret the string as a json-encoded hash or array. When I read the field back, I get the hash or array instead of the string representation.
I'm going to suggest that assigning an arbitrary string to a Json field should result in a validation error rather than an exception.
I have a class defined as follows:
Assigning a hash or an array to jsonfield works as expected. The hash or array is properly json-ized in the data store, and when I read the field back, I get a hash/array that's identical to the original.
Assigning a string to jsonfield causes the parser to interpret the string as a json-encoded hash or array. When I read the field back, I get the hash or array instead of the string representation.
Assigning a string that is not a valid json representation of a hash or array raises an exception.
I would expect this last case to result in a validation error, not an exception.
For comparison, no exception is raised when I assign "Nancy" to id. It simply won't validate.