This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Pages: 1 - Last Post: 29 Nov 25, 13:11 Last Post By: davidekholm
RobM

Posts: 4,087
Registered: 4-Aug-2006
Views in json data
Posted: 26 Nov 25, 22:44
 
  Click to reply to this thread Reply
Is it possible to make the JSONMaker call exclude view results? It would make it very easy for me to then parse the json data (albumData) without having to exclude all view results when doing a search of the data.
jm = new JSONMaker(engine);
albumData = jm.getTreeAsString(rootFolder);

A single album object appears in the albumData multiple times when views are used in a project.
davidekholm

Posts: 4,023
Registered: 18-Oct-2002
Re: Views in json data
Posted: 28 Nov 25, 16:35   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
Is it possible to make the JSONMaker call exclude view results? It would make it very easy for me to then parse the json data (albumData) without having to exclude all view results when doing a search of the data.
jm = new JSONMaker(engine);
albumData = jm.getTreeAsString(rootFolder);

A single album object appears in the albumData multiple times when views are used in a project.

I'll add a filtering mechanism for v38.2. You can try it already by getting the latest beta core file.

Usage:
jm = new JSONMaker(engine)
jm.setFilter(JSONMaker.NO_VIEWS_FILTER);
s = jm.getTreeAsString(currentFolder)

Pass null to reset the filter to no filtering. You can pass any object that matches Predicate<AlbumObject> to the filter in order to filter on arbitrary things.
RobM

Posts: 4,087
Registered: 4-Aug-2006
Re: Views in json data
Posted: 28 Nov 25, 16:38   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
RobM wrote:
Is it possible to make the JSONMaker call exclude view results? It would make it very easy for me to then parse the json data (albumData) without having to exclude all view results when doing a search of the data.
jm = new JSONMaker(engine);
albumData = jm.getTreeAsString(rootFolder);

A single album object appears in the albumData multiple times when views are used in a project.

I'll add a filtering mechanism for v38.2. You can try it already by getting the latest beta core file.

Usage:

jm = new JSONMaker(engine)
jm.setFilter(JSONMaker.NO_VIEWS_FILTER);
s = jm.getTreeAsString(currentFolder)

Pass null to reset the filter to no filtering. You can pass any object that matches Predicate<AlbumObject> to the filter in order to filter on arbitrary things.
Brilliant, thanks. That will certainly make it easier as I now won't have to adjust my code.
davidekholm

Posts: 4,023
Registered: 18-Oct-2002
Re: Views in json data
Posted: 28 Nov 25, 17:13   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Following up on the meaning of Predicate<AlbumObject>: As Java is object oriented, everything has to be a class, so the filter is an instance of the Predicate class, and specifically a Predicate that takes an AlbumObject as parameter. Luckily, with Groovy and Java 8+, you can use practical "Lambda expressions" to produce filters. Here's how to filter for images only:
jm.setFilter(ao -> ao.category == Category.image);
RobM

Posts: 4,087
Registered: 4-Aug-2006
Re: Views in json data
Posted: 28 Nov 25, 18:08   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Following up on the meaning of Predicate<AlbumObject>: As Java is object oriented, everything has to be a class, so the filter is an instance of the Predicate class, and specifically a Predicate that takes an AlbumObject as parameter. Luckily, with Groovy and Java 8+, you can use practical "Lambda expressions" to produce filters. Here's how to filter for images only:
jm.setFilter(ao -> ao.category == Category.image);
Thanks. I can read that now without getting a headache! ;)
davidekholm

Posts: 4,023
Registered: 18-Oct-2002
Re: Views in json data
Posted: 29 Nov 25, 13:11   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Rob, I noticed that the UI hangs when printing huge JSON output to the system console. The JSONMaker is super fast, but the component used for logging isn't optimised for long lines. It's now replaced by a super fast component, see https://jalbum.net/forum/thread.jspa?messageID=372617&#372617

(Also added pretty printing of JSON output)
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums