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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
44965ffe9bd201e8a82de00f8dd9cf73?d=identicon&s=25 jamie (Guest)
on 2008-12-31 16: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.