Forum: Ruby on Rails change attribute names in serialized output - to_xml or to_json

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
jamie (Guest)
on 2008-12-31 17:56
(Received via mailing list)
When serializing an object, is there a way to change the name of an
attribute outputted without changing the underlying model (i.e.. I do
not want to change model attributes or methods?  I have a class that
has an association called materials... I would like the tag generated
when I call to_xml to be <contents> vs <materials>.  Another example
is I have a method called get_url... I would like the tag to be <url>
vs <get_url>...
This topic is locked and can not be replied to.