Tencent/APIJSON · error · IllegalArgumentException
{}/{}:{} 的深度(或者说层级) 为 {} 已超限,必须在 1-{} 内 !
Error message
{}/{}:{} 的深度(或者说层级) 为 {} 已超限,必须在 1-{} 内 ! What it means
onObjectParse tracks the deepest response path (parentPath segments + 1). When position==0 (a new main-array item level) and the accumulated queryDepth exceeds getMaxQueryDepth(), IllegalArgumentException is thrown listing the path and the allowed 1..max range. It is a resource guard preventing exponential nested queries.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractParser.java:1169
if (Log.DEBUG) {
Log.i(TAG, "\ngetObject: parentPath = " + parentPath
+ ";\n name = " + name + "; request = " + JSON.toJSONString(request));
}
if (request == null) {// Moment:{} || request.isEmpty()) {//key-value条件
return null;
}
int type = arrayConfig == null ? 0 : arrayConfig.getType();
int position = arrayConfig == null ? 0 : arrayConfig.getPosition();
String[] arr = StringUtil.split(parentPath, "/");
if (position == 0) {
int d = arr == null ? 1 : arr.length + 1;
if (queryDepth < d) {
queryDepth = d;
int maxQueryDepth = getMaxQueryDepth();
if (queryDepth > maxQueryDepth) {
throw new IllegalArgumentException(parentPath + "/" + name + ":{} 的深度(或者说层级) 为 " + queryDepth + " 已超限,必须在 1-" + maxQueryDepth + " 内 !");
}
}
}
apijson.orm.Entry<String, String> entry = Pair.parseEntry(name, true);
String table = entry.getKey(); //Comment
// String alias = entry.getValue(); //to
boolean isTable = isTableKey(table);
boolean isArrayMainTable = isSubquery == false && isTable && type == SQLConfig.TYPE_ITEM_CHILD_0 && arrayConfig != null && RequestMethod.isGetMethod(arrayConfig.getMethod(), true);
boolean isReuse = isArrayMainTable && position > 0;
ObjectParser<T, M, L> op = null;
if (isReuse) { // 数组主表使用专门的缓存数据
op = arrayObjectParserCacheMap.get(parentPath.substring(0, parentPath.lastIndexOf("[]") + 2));
op.setParentPath(parentPath);
}
View on GitHub (pinned to 5284052872)
Solutions
- Reduce nesting: split the deep query into several shallower requests and join client-side by id
- Use引用赋值 (reference assignment, key@) to reuse sibling objects instead of re-querying deeper
- Raise getMaxQueryDepth() server-side (override in your Parser subclass) if the depth is legitimate — weigh the DoS risk
- Prefer POST S single-table queries for the deepest data instead of one monolithic tree
Example fix
// before (depth 6+)
{"[]":{"Comment[]":{"0":{"User":{"Moment":{"Comment[]":{...}}}}}}}
// after: two requests
{"Comment[]":{"@column":"id,userId","@order":"id-"}}
then {"User":{"id{}@":"/Comment[]/userId"}} Defensive patterns
Strategy: validation
Validate before calling
int depth = countNesting(requestJson); // walk [] and object children
if (depth > MAX_QUERY_DEPTH) throw new IllegalStateException("query too deep: " + depth); Type guard
boolean withinQueryDepth(JsonNode n, int max) {
return measureDepth(n) <= max;
} Try / catch
catch (IllegalArgumentException e) { if (e.getMessage().contains("已超限")) { splitQuery(e.getMessage()); } else throw e; } Prevention
- Split deep trees into multiple flat requests joined by id@
- Cache the configured getMaxQueryDepth() client-side and assert against it
- Prefer keyset pagination over deep nesting for graphs
When it happens
Trigger: Nesting arrays/objects deeper than the configured limit, e.g. [] -> 0:{} -> Comment[] -> 0:{} -> Comment:{} ... beyond maxQueryDepth (default 5). Each new level of a page-array item at position 0 increments the counter.
Common situations: Client builds recursive self-referencing structures (Comment -> reply User[] -> Moment[] -> Comment[]...); migrating from a version with a higher default depth; lowering maxQueryDepth in production for DoS protection and breaking existing deep queries; @combine of deep subqueries.
Related errors
- @join:'{}' 对应的 {} 不是合法的数组 key[] !@ APP JOIN 最多允许跨 1 层,只能是子数组
- Value for key '" + key + "' is not a Map: " + value.getClass
- Value for key '" + key + "' is not a List: " + value.getClas
- Cannot convert String value '" + value + "' to int: " + e.ge
- Cannot convert value of type " + value.getClass().getName()
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/4e8d97951b665333.
Report an issue: GitHub.