Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:APIJSON APIJSON AbstractParser onArrayParse

From Leeroopedia
Knowledge Sources
Domains ORM, Pagination, Request_Processing
Last Updated 2026-10-11 00:00 GMT

Overview

Concrete array parser that processes key[] paginated query directives, extracting page/count/query parameters, enforcing limits, and orchestrating per-item object parsing within the array context, provided by the APIJSON ORM framework.

Description

The onArrayParse' method on AbstractParser handles array-keyed (key[]) request objects. It:

  1. Extracts pagination parameters: query (0=TABLE, 1=TOTAL, 2=ALL), count (items per page), page (page number), join
  2. Validates against limits: getMaxQueryPage(), getMaxQueryCount(), getMinQueryPage()
  3. Creates a SQLConfig with the array context (type, position, count, page)
  4. Iterates up to count times, calling onObjectParse for each item
  5. For query=1 (TOTAL) or query=2 (ALL): executes an additional count query
  6. Extracts child table data from the first item if the array key matches a table name (optimization for Table[]: { Table: {} })
  7. Restores removed pagination keys after processing

The method also handles the compat flag for aggregate function pagination compatibility.

Usage

Called internally by AbstractObjectParser.onChildParse() when encountering array keys. Not typically called directly.

Code Reference

Source Location

  • Repository: APIJSON
  • File: src/main/java/apijson/orm/AbstractParser.java

Signature

public L onArrayParse(
    M request,
    String parentPath,
    String name,
    boolean isSubquery,
    L cache
) throws Exception

Parameters:

  • request - The array config object with pagination keys and table objects
  • parentPath - Path from root to parent
  • name - Array key name (e.g., "Comment[]")
  • isSubquery - Whether this array is inside a subquery
  • cache - Result cache list

Returns: L (List<Object>) - Array of results

Import

import apijson.orm.AbstractParser;

I/O Contract

Inputs

Name Type Required Description
request M Yes Array config with pagination keys
query String No "0"=TABLE, "1"=TOTAL, "2"=ALL
count Integer No Items per page
page Integer No Page number (0-based)
join Object No Join directive

Outputs

Name Type Description
return L (List<Object>) Array of result items
total int Total count (when query=1 or 2)
info M Pagination info (total, count, page, max, more, first, last)

Usage Examples

Paginated Query

// Request: {
//   "[]": {
//     "count": 5,
//     "page": 0,
//     "Moment": {}
//   }
// }
// onArrayParse extracts: query=TABLE, count=5, page=0
// Creates SQLConfig with count=5, page=0
// Calls onObjectParse 5 times (or until empty result)
// Returns: [ { Moment: {...} }, { Moment: {...} }, ... ]

Total Count Query

// Request: {
//   "[]": {
//     "count": 5,
//     "page": 0,
//     "query": 2,          // ALL: both data and total
//     "Moment": {}
//   }
// }
// Executes:
// 1. HEAD query for total: SELECT count(*) FROM Moment
// 2. Data query: SELECT * FROM Moment LIMIT 5 OFFSET 0
// Puts total and pagination info in queryResultMap

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment