2014-09-04 12:04 GMT+02:00 Peter Björkman <[email protected]>: > Hi! I have question about how JSONResult (or specifically JSONWriter) > handles Iteratable objects. It treats them as having no other methods than > containing other objects. But most Iteratable objects have more to them > than that, but those methods are impossible to output as JSON. > > In JSONWriter.process() (line 155): > } else if (object instanceof Iterable) { > this.array(((Iterable) object).iterator(), method); > > The array() method just adds the objects returned from the iterator. But > what if we need some other property? > > Is there a way to do this? More specifically, we have a PaginatedCollection > used for paging - it's an Iteratable, but also contains methods like: > getTotalSize() > getNextPage() > getLastPage() > and so on. > > Any ideas on how to serialize such an object to JSON? Shouldn't JSONWriter > treat an Iteratable as a bean with something like entries added to it? Like > this: > > paginatedCollection : { totalSize : 100, nextPage : 5, lastPage : 10, > entries: [{item :1}, item : 2}] }
You can try to wrap your iterable with a bean which will expose entries (as Iterable) and paginatedCollection (as a bean) Regards -- Łukasz + 48 606 323 122 http://www.lenart.org.pl/ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

