I'm using Ruby with Sinatra and DataMapper. It is simple enough to create a "get" webservice that delivers a data set to a UI with something like Item.all().to_json
However, the intent is for the UI to use the data set for crud work and return a single JSON object for add or update. I haven't found an equivalent "from_json" DataMapper function to initialize an Item object.
As a work-around, I'm using JSON.parse, like this:
item_data = JSON.parse(request.body.read, :quirks_mode => true)
This works, but then I have to create a new DataMapper object, i.e. item = Item.new
,
and copy all the elements from item_data to item, but I'd like to think there's a simpler way.
Any and all suggestions are welcome.