Tencent/APIJSON · error · IllegalArgumentException
{method}请求,{name}/{key} 里面的 {idInKey}:value 中value的类型只能是 [Lo
Error message
{method}请求,{name}/{key} 里面的 {idInKey}:value 中value的类型只能是 [Long] ! What it means
Thrown by verifyId when the batch key id{} exists but its value cannot be read as a List — get(robj, "id{}") threw internally. APIJSON requires id{} to be a JSON array of ids for batch UPDATE/DELETE so it can build an IN (...) clause.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java:763
@NotNull String method, @NotNull String name, @NotNull String key
, @NotNull M robj, @NotNull String idKey, final int maxUpdateCount, boolean atLeastOne) throws Exception {
//单个修改或删除
Object id = robj.get(idKey); //如果必须传 id ,可在Request表中配置NECESSARY
if (id != null && id instanceof Number == false && id instanceof String == false) {
throw new IllegalArgumentException(method + "请求," + name + "/" + key
+ " 里面的 " + idKey + ":value 中value的类型只能是 Long 或 String !");
}
//批量修改或删除
String idInKey = idKey + "{}";
// id引用, 格式: "id{}@": "sql"
String idRefInKey = getString(robj, idKey + "{}@");
L idIn = null;
try {
idIn = get(robj, idInKey); //如果必须传 id{} ,可在Request表中配置NECESSARY
} catch (Exception e) {
throw new IllegalArgumentException(method + "请求," + name + "/" + key
+ " 里面的 " + idInKey + ":value 中value的类型只能是 [Long] !");
}
if (idIn == null) {
if (atLeastOne && id == null && idRefInKey == null) {
throw new IllegalArgumentException(method + "请求," + name + "/" + key
+ " 里面 " + idKey + "," + idInKey + "," + (idKey + "{}@") + " 至少传其中一个!");
}
} else {
if (idIn.size() > maxUpdateCount) { //不允许一次操作 maxUpdateCount 条以上记录
throw new IllegalArgumentException(method + "请求," + name + "/" + key
+ " 里面的 " + idInKey + ":[] 中[]的长度不能超过 " + maxUpdateCount + " !");
}
//解决 id{}: ["1' OR 1='1'))--"] 绕过id{}限制
//new ArrayList<Long>(idIn) 不能检查类型,Java泛型擦除问题,居然能把 ["a"] 赋值进去还不报错
for (int i = 0; i < idIn.size(); i++) {
Object o = idIn.get(i);
if (o == null) {
throw new IllegalArgumentException(method + "请求," + name + "/" + keyView on GitHub (pinned to 5284052872)
Solutions
- Send id{} as a JSON array: {"User":{"id{}":[1,2,3]}}
- If you only target one record, use the plain id key instead of id{}
- Verify no middleware stringifies array body values
Example fix
// before
{"User":{"id{}":"1,2,3","name":"a"}}
// after
{"User":{"id{}":[1,2,3],"name":"a"}} Defensive patterns
Strategy: validation
Validate before calling
function assertIdInArray(obj, idKey = 'id') {
const v = obj[idKey + '{}'];
if (v != null && !Array.isArray(v)) throw new TypeError(idKey + '{} must be an array');
} Type guard
const isIdIn = (obj, idKey = 'id') => { const v = obj[idKey + '{}']; return v == null || Array.isArray(v); }; Try / catch
catch (e) { if (/id\{}.*\[Long\]/.test(e.message)) convertToListOrRetryWithArray(); else throw e; } Prevention
- Never join ids into a comma string; keep them in a JSON array
- Send bodies with Content-Type: application/json so arrays survive transport
When it happens
Trigger: PUT/DELETE with {"User":{"id{}": "1,2,3"}} (string instead of array) or {"User":{"id{}": 12}} (scalar) or {"User":{"id{}": {"1":2}}} (object).
Common situations: Client joins ids into a comma-separated string; older client sent a single id to the batch key; a form encoder turned the array into a string before reaching the server.
Related errors
- 批量新增/修改失败!{}/{}:value 中value不合法!类型必须是 OBJECT ,结构为 {} !
- {method}请求,{name}/{key} 里面的 {idInKey}:[] 中所有项都不能为 [ null, <=
- {method}请求,{name}/{key} 里面的 {idInKey}:[] 中所有项的类型都只能是 Long 或
- Cannot convert value of type " + value.getClass().getName()
- 字符 " + function + " 不合法!
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/f23285733535e94d.
Report an issue: GitHub.