Tencent/APIJSON · error · IllegalArgumentException

{} 内截至 {}:{} 时数组对象 key[]:{} 的数量达到 {} 已超限,必须在 0-{} 内 !

Error message

{} 内截至 {}:{} 时数组对象 key[]:{} 的数量达到 {} 已超限,必须在 0-{} 内 !

What it means

A DoS guard: each object parser counts array-key occurrences ('key[]:{}') and compares against parser.getMaxArrayCount(), whose default is AbstractParser.MAX_ARRAY_COUNT = 5. When the count of array objects exceeds the limit, parsing aborts with this message showing the current count and the max. Note the counter only increments when arrayConfig == null or position == 0, so nested array items don't double count.

Source

Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java:612

	@Override
	public Object onChildParse(int index, String key, M value, Object cache) throws Exception {
		boolean isFirst = index <= 0;
		boolean isMain = isFirst && type == TYPE_ITEM;

		Object child;
		boolean isEmpty;

		if (JSONMap.isArrayKey(key)) { // APIJSON Array
			if (isMain) {
				throw new IllegalArgumentException(parentPath + "/" + key + ":{} 不合法!"
						+ "数组 []:{} 中第一个 key:{} 必须是主表 TableKey:{} !不能为 arrayKey[]:{} !");
			}

			if (arrayConfig == null || arrayConfig.getPosition() == 0) {
				arrayCount ++;
				int maxArrayCount = parser.getMaxArrayCount();
				if (arrayCount > maxArrayCount) {
					throw new IllegalArgumentException(path + " 内截至 " + key + ":{} 时数组对象 key[]:{} "
                            + "的数量达到 " + arrayCount + " 已超限,必须在 0-" + maxArrayCount + " 内 !");
				}
			}

			String query = getString(value, KEY_QUERY);
			child = parser.onArrayParse(value, path, key, isSubquery, cache instanceof List<?> ? (L) cache : null);
			isEmpty = child == null || ((List<?>) child).isEmpty();

			if ("2".equals(query) || "ALL".equals(query)) { // 不判断 isEmpty,因为分页数据可能只是某页没有
				String totalKey = JSONResponse.formatArrayKey(key) + "Total";
				String infoKey = JSONResponse.formatArrayKey(key) + "Info";
				if ((request.containsKey(totalKey) || request.containsKey(infoKey)
						|| request.containsKey(totalKey + "@") || request.containsKey(infoKey + "@")) == false) {
					// onParse("total@", "/" + key + "/total");
					// onParse(infoKey + "@", "/" + key + "/info");
					// 替换为以下性能更好、对流程干扰最小的方式:

					String keyPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, "/" + key);

View on GitHub (pinned to 5284052872)

Solutions

  1. Split the request into multiple API calls so each stays within the array-count limit.
  2. Raise the limit server-side if legitimate: override getMaxArrayCount() in your AbstractParser subclass (or set AbstractParser.MAX_ARRAY_COUNT) — weigh the query-explosion risk first.
  3. Prefer one array with joins/associations instead of many parallel arrays.

Example fix

// before
{ "a[]": {...}, "b[]": {...}, "c[]": {...}, "d[]": {...}, "e[]": {...}, "f[]": {...} }
// after
// request 1: a[],b[],c[] ; request 2: d[],e[],f[]
Defensive patterns

Strategy: validation

Validate before calling

int arrays = 0;
for (String k : request.keySet()) if (k.endsWith("[]")) arrays++;
int max = 5; // mirror parser.getMaxArrayCount()
if (arrays > max) throw new IllegalArgumentException("too many arrays (" + arrays + " > " + max + "), split the request");

Type guard

function withinArrayLimit(obj: Record<string, unknown>, max = 5): boolean {
  return Object.keys(obj).filter(k => k.endsWith('[]')).length <= max;
}

Prevention

When it happens

Trigger: A single request object containing 6+ distinct 'xxx[]' keys (e.g. six parallel lists), reaching the 6th array key and exceeding the default max of 5.

Common situations: Dashboard/aggregate endpoints fetching many lists in one request; decreasing limits in a shared parser; combining several previously separate list requests into one batch call.

Related errors


AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14). Data as JSON: /api/errors/7c71d958a17a2ee8. Report an issue: GitHub.