Implementation:APIJSON APIJSON AbstractParser onObjectParse
| Knowledge Sources | |
|---|---|
| Domains | ORM, Request_Processing, Recursive_Parsing |
| Last Updated | 2026-10-11 00:00 GMT |
Overview
Concrete recursive object parser that processes each table-keyed node in the request JSON tree, creating per-object parsers and executing SQL within the transaction, provided by the APIJSON ORM framework.
Description
The onObjectParse method on AbstractParser is the recursive heart of the request processing pipeline. For each table-keyed object in the request JSON, it:
- Parses the table name and optional alias from the key (e.g., Comment:to → table=Comment, alias=to)
- Creates or reuses an ObjectParser instance
- Sets the per-object method override (via @method directive)
- Calls ObjectParser.parse() to process all key-value pairs
- Executes SQL (setSQLConfig().executeSQL().response())
- Handles array context (pagination, total count, pagination info)
- Caches array main table parsers for reuse across pages
The method enforces a maximum query depth (getMaxQueryDepth()) to prevent excessively deep nested queries.
Usage
Called internally by parseResponse for the root object and recursively for child table objects. Override onObjectParse in a subclass to customize the recursive parsing behavior, such as adding custom logging or modifying the object parser before parsing.
Code Reference
Source Location
- Repository: APIJSON
- File: src/main/java/apijson/orm/AbstractParser.java
Signature
public M onObjectParse(
final M request,
String parentPath,
String name,
final SQLConfig<T, M, L> arrayConfig,
boolean isSubquery,
M cache
) throws Exception
Parameters:
- request - The object map to parse (table conditions and child objects)
- parentPath - Path from root to this object's parent (e.g., /[]/0), null for root
- name - Key name in format Table:alias (e.g., Comment:to)
- arrayConfig - SQL config from parent array context, null for non-array objects
- isSubquery - Whether this object is part of a subquery
- cache - SQL result cache map
Returns: M - Response map with SQL results for this table and all child tables
Import
import apijson.orm.AbstractParser;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| request | M (Map<String,Object>) | Yes | Object to parse with table conditions |
| parentPath | String | No | Path from root, null for root object |
| name | String | No | Key name in Table:alias format |
| arrayConfig | SQLConfig | No | Array context config (null for non-array) |
| isSubquery | boolean | Yes | Whether this is a subquery |
| cache | M | No | SQL result cache |
Outputs
| Name | Type | Description |
|---|---|---|
| return | M (Map<String,Object>) | Response with table data and nested child results |
Usage Examples
Array Context with Pagination
// Request: { "[]": { "count": 5, "page": 0, "Moment": {} } }
// onObjectParse is called for each Moment in the array:
// onObjectParse(momentRequest, "/[]/0", "Moment", arrayConfig, false, null)
// Returns: { "Moment": { "id": 1, "content": "Hello", ... } }
// For array main table at position > 0, the parser is reused from cache:
// op = arrayObjectParserCacheMap.get(parentPath.substring(0, lastIndexOf("[]") + 2));
Total Count Query
// When query=2 (ALL), onObjectParse first executes a HEAD/count query:
// int total = getIntValue(rp, JSONResponse.KEY_COUNT);
// putQueryResult(pathPrefix + JSONResponse.KEY_TOTAL, total);
// Then executes the actual data query for the page