struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Björkman <pe...@josh.se>
Subject JSONResult with an Iteratable...
Date Thu, 04 Sep 2014 10:04:41 GMT
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}] }



Regards
Peter Björkman

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message