Tencent/APIJSON · error · IllegalArgumentException

:'/targetTable/targetKey' 中 targetTable 值…

Error message

${e.getKey()}:'/targetTable/targetKey' 中 targetTable 值 ${targetTable} 不合法!必须满足大写字母开头的表对象英文单词 key 格式!

What it means

The table segment of a reference path ('/targetTable/targetKey', optionally 'Table:alias') is parsed with Pair.parseEntry and its table part must satisfy StringUtil.isName — an identifier starting with an uppercase letter, as APIJSON table object keys are conventionally uppercase ('User', 'Comment'). This IllegalArgumentException fires for lowercase or malformed table names.

Solutions

  1. Use the uppercase table object key exactly as it appears in the request: '/User/id' not '/user/id'
  2. If a serializer rewrites keys, disable case transformation for APIJSON requests
  3. Check for stray characters or digits at the start of the table segment

Example fix

// before
{ 'join': '</Moment', 'Moment': { 'userId@': '/user/id' } }
// after
{ 'join': '</Moment', 'Moment': { 'userId@': '/User/id' } }
Defensive patterns

Strategy: validation

Validate before calling

const TABLE_RE = /^[A-Z][A-Za-z0-9_]*$/;
function checkRefTables(req) {
  for (const tbl of Object.values(req)) {
    if (tbl && typeof tbl === 'object') {
      for (const [k, v] of Object.entries(tbl)) {
        if (!k.endsWith('@') || typeof v !== 'string' || !v.startsWith('/')) continue;
        const t = v.split('/')[1].split(':')[0];
        if (!TABLE_RE.test(t)) return `${k}: targetTable '${t}' must be an uppercase-initial table key`;
      }
    }
  }
  return null;
}

Type guard

const isValidTargetTable = (seg) => /^[A-Z][A-Za-z0-9_]*$/.test(seg);

Try / catch

Catch IllegalArgumentException containing 'targetTable 值'; correct the case of the table key to match the declared object.

Prevention

When it happens

Trigger: 'userId@': '/user/id' (lowercase table), '/0User/id' (starts with digit), '/Us er/id' (space). Note: isName only checks identifier shape; conventionally the library expects uppercase-initial table keys, as the message states.

Common situations: Using the physical DB table name (often lowercase) instead of the JSON table-object key; auto-lowercasing keys with a serializer (e.g. Jackson/ Gson lower-case strategies); renaming table objects in the request but not the reference paths.

Related errors


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

Appendix: source

Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractParser.java:1830

					throw new IllegalArgumentException(e.getKey() + ":value 中 value 值 " + targetPath + " 不合法!必须为引用赋值的路径 '/targetTable/targetKey' !");
				}

				// 取出引用赋值路径 targetPath 对应的 Table 和 key
				index = targetPath.lastIndexOf("/");
				String targetKey = index < 0 ? null : targetPath.substring(index + 1);
				if (StringUtil.isName(targetKey) == false) {
					throw new IllegalArgumentException(e.getKey() + ":'/targetTable/targetKey' 中 targetKey 值 " + targetKey + " 不合法!必须满足英文单词变量名格式!");
				}

				targetPath = targetPath.substring(0, index);
				index = targetPath.lastIndexOf("/");
				String targetTableKey = index < 0 ? targetPath : targetPath.substring(index + 1);

				// 主表允许别名
				apijson.orm.Entry<String, String> targetEntry = Pair.parseEntry(targetTableKey, true);
				String targetTable = targetEntry.getKey(); //User
				if (StringUtil.isName(targetTable) == false) {
					throw new IllegalArgumentException(e.getKey() + ":'/targetTable/targetKey' 中 targetTable 值 " + targetTable + " 不合法!必须满足大写字母开头的表对象英文单词 key 格式!");
				}

				String targetAlias = targetEntry.getValue(); //owner
				if (StringUtil.isNotEmpty(targetAlias, true) && StringUtil.isName(targetAlias) == false) {
					throw new IllegalArgumentException(e.getKey() + ":'/targetTable:targetAlias/targetKey' 中 targetAlias 值 " + targetAlias + " 不合法!必须满足英文单词变量名格式!");
				}

				//targetTable = targetTableKey;  // 主表允许别名
				if (StringUtil.isName(targetTable) == false) {
					throw new IllegalArgumentException(e.getKey() + ":'/targetTable/targetKey' 中 targetTable 值 " + targetTable + " 不合法!必须满足大写字母开头的表对象英文单词 key 格式!");
				}

				//对引用的JSONObject添加条件
				Map<String, Object> targetObj;
				try {
					targetObj = JSON.get(request, targetTableKey);
				}
				catch (Exception e2) {

View on GitHub (pinned to 5284052872)