#363 - Add convenience methods for json parsing/formatting to generated objects
This commit is contained in:
1 parent
07ca6e8ca0
commit
47a02e897e
3 files changed
+72
No files matched your search
@@ -122,6 +122,24 @@ module Google
|
||||
include Representable::JSON
|
||||
feature JsonRepresentationSupport
|
||||
end
|
||||
|
||||
module JsonObjectSupport
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def from_json(json)
|
||||
representation = self.const_get(:Representation)
|
||||
representation.new(self.new).from_json(json, unwrap: self)
|
||||
end
|
||||
end
|
||||
|
||||
def to_json
|
||||
representation = self.class.const_get(:Representation)
|
||||
representation.new(self).to_json(skip_undefined: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -7,6 +7,8 @@ class <%= cls.generated_class_name %>
|
||||
<%= indent(include('representation_stub', :cls => child_class), 2) -%>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
|
||||
include Google::Apis::Core::JsonObjectSupport
|
||||
end
|
||||
<% elsif cls.items && cls.items._ref.nil? -%>
|
||||
<%= include('representation_stub', :cls => cls.items, :api => api) -%>
|
||||
|
||||
Reference in new issue
Block a user