84
84
# If the result is a web service collection, serve only one
85
85
# batch of the collection.
86
86
collection = getMultiAdapter((result, self.request), ICollection)
87
result = CollectionResource(collection, self.request).batch()
87
result = CollectionResource(collection, self.request).batch() + '}'
88
88
elif self.should_batch(result):
89
result = self.batch(result, self.request)
91
# Serialize the result to JSON. Any embedded entries will be
92
# automatically serialized.
94
json_representation = simplejson.dumps(
95
result, cls=ResourceJSONEncoder)
97
raise TypeError("Could not serialize object %s to JSON." %
89
result = self.batch(result, self.request) + '}'
91
# Serialize the result to JSON. Any embedded entries will be
92
# automatically serialized.
94
result = simplejson.dumps(result, cls=ResourceJSONEncoder)
96
raise TypeError("Could not serialize object %s to JSON." %
100
99
self.request.response.setStatus(200)
101
100
self.request.response.setHeader('Content-Type', self.JSON_TYPE)
102
return json_representation
104
103
def should_batch(self, result):
105
104
"""Whether the given response data should be batched."""