Tencent/APIJSON · error · IllegalArgumentException

{method}请求,请在 {name} 内传 {key}:[{ ... }] ,批量新增 Table[]:value

Error message

{method}请求,请在 {name} 内传 {key}:[{ ... }] ,批量新增 Table[]:value 中 value 必须是包含表对象的非空数组!其中每个子项 { ... } 都是 tag:{tag} 对应单个新增的 structure !

What it means

In onParseJSONArray during structure validation: for POST or PUT on a batch array key (ending in '[]', e.g. "Comment[]"), the request array must be non-null and non-empty, and each element an object representing one row. A null/empty array throws IllegalArgumentException explaining that Table[]:value must be a non-empty array of table objects tagged by the base key.

Source

Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java:721

						Boolean atLeastOne = tobj == null ? null : getBoolean(tobj, Operation.IS_ID_CONDITION_MUST.name());
						if (Boolean.TRUE.equals(atLeastOne) || RequestMethod.isUpdateMethod(method)) {
							verifyId(method.name(), name, key, robj, finalIdKey, maxUpdateCount, atLeastOne != null ? atLeastOne : IS_UPDATE_MUST_HAVE_ID_CONDITION);

							String userIdKey = idCallback == null ? null : idCallback.getUserIdKey(db, ds, ns, cl, sh, key);
							String finalUserIdKey = StringUtil.isEmpty(userIdKey, false) ? KEY_USER_ID : userIdKey;
							verifyId(method.name(), name, key, robj, finalUserIdKey, maxUpdateCount, false);
						}
					}
				}

				return verifyRequest(method, key, tobj, robj, maxUpdateCount, database, datasource, namespace, catalog, schema, idCallback, parser);
			}

			@Override
			protected L onParseJSONArray(String key, L tarray, L rarray) throws Exception {
				if ((method == POST || method == PUT) && isArrayKey(key)) {
					if (rarray == null || rarray.isEmpty()) {
						throw new IllegalArgumentException(method + "请求,请在 " + name + " 内传 " + key + ":[{ ... }] "
								+ ",批量新增 Table[]:value 中 value 必须是包含表对象的非空数组!其中每个子项 { ... } 都是"
								+ " tag:" + key.substring(0, key.length() - 2) + " 对应单个新增的 structure !");
					}
					if (rarray.size() > maxUpdateCount) {
						throw new IllegalArgumentException(method + "请求," + name + "/" + key
								+ " 里面的 " + key + ":[{ ... }] 中 [] 的长度不能超过 " + maxUpdateCount + " !");
					}
				}
				return super.onParseJSONArray(key, tarray, rarray);
			}
		});

	}

	/**
	 * @param method
	 * @param name
	 * @param key

View on GitHub (pinned to 5284052872)

Solutions

  1. Populate the array with at least one table object: {"Comment[]": [{"content":"a"}, {"content":"b"}]}.
  2. Skip the request entirely client-side when there is nothing to insert — do not send an empty batch.
  3. For PUT-style partial updates, ensure each element still contains the id condition needed by verifyId.

Example fix

// before
POST { "Comment[]": [], "tag": "Comment[]" }

// after
POST { "Comment[]": [ { "momentId": 1, "content": "hi" } ], "tag": "Comment[]" }
Defensive patterns

Strategy: validation

Validate before calling

if ((method == POST || method == PUT) && key.endsWith("[]")
        && (arr == null || arr.isEmpty())) {
    clientError("batch key " + key + " requires a non-empty array of objects");
}

Type guard

boolean isNonEmptyBatchArray(String key, List<Object> arr, RequestMethod m) { return !(m == RequestMethod.POST || m == RequestMethod.PUT) || !key.endsWith("[]") || (arr != null && !arr.isEmpty()); }

Try / catch

catch (IllegalArgumentException e) when message contains "批量新增" -> 400; skip the call when the selection is empty rather than sending [].

Prevention

When it happens

Trigger: A POST/PUT sends {"Comment[]": []} or omits the array while the structure/request uses the batch form; isArrayKey(key) is true for the method and rarray == null || rarray.isEmpty() triggers the throw.

Common situations: UI 'add all' flow with an empty selection serializing as []; client omits the key when the list is empty but the tag still targets the batch key; refactoring from single-object to batch form leaving [] placeholders.

Related errors


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