struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Björkman <pe...@josh.se>
Subject Re: JSONResult with an Iteratable...
Date Thu, 04 Sep 2014 13:39:00 GMT
Thanks Lukasz, probably the easiest way!

Regards
Peter


On Thu, Sep 4, 2014 at 1:31 PM, Lukasz Lenart <lukaszlenart@apache.org>
wrote:

> 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
>
>


-- 
PETER BJÖRKMAN - CTO / SYSTEMS ARCHITECT
josh / together is better / www.josh.se
gävlegatan 12b / 113 30 stockholm / sweden
phone +46 709 687 884 / skype peter_josh

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