JSON Mapping

This recipe will help you to setup a basic JSON Mapping in your application.
First you need an amber project generated with Amber CLI or from scratch.
You can use JSON.mapping to directly create an object from JSON:
Then in your routes file:
Alternatively you can use response_with helper. Here you don't need to setup content_type, however the requested path requires a .json extension, by example /json_mapping.json
class SomeController < ApplicationController
def json_mapping
return "empty body" if request.body.to_s.blank?
user = User.from_json request.body.to_s
user.username += "mapped!"
response_with do
json user.to_json