to_xml and to_json behaviour with nil values

Hi,

i was wondering if there is any way to just skip attributes having nil
values when to_xml or to_json on ActiveRecord.
The default behavior is to include a nil value:
xml:
<identity-url nil="true"/>
json:
"identity_url": null

Is there an option way to make this value just not appear ? Or should
it be a hack in the serialization itself ?
Thank you,

Elise