rails/jbuilder — pull request #38 by johnlcox (2012-04-26 21:45:37+00:00)
Title: Added methods to turn off serialization of nil attributes

This adds the ability to turn off serialization of nil attributes by default or on a per instance basis via a class and instance method respectively. The default behavior if neither method is called is to continue serializing nil attributes.

``` ruby
# You can set the default behavior of all Jbuilder instances to not serialize nil
Jbuilder.serialize_nil false

json.author do |json|
json.name nil
json.age 32
end
# => { author: {"age": 32 } }

# Or you can set the behavior per instance
json.author do |json|
json.serialize_nil! false
json.name nil
json.age 32
end
# => { author: {"age": 32 } }
```