struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukasz Lenart <lukaszlen...@apache.org>
Subject Re: JSONResult with an Iteratable...
Date Thu, 04 Sep 2014 11:31:27 GMT
2014-09-04 12:04 GMT+02:00 Peter Björkman <peter@josh.se>:
> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message