Tencent/APIJSON · error · IllegalArgumentException

{name}: { IF: value } 中 value 类型错误!只允许 String, JSONRequest!

Error message

{name}: { IF: value } 中 value 类型错误!只允许 String, JSONRequest!

What it means

Thrown while parsing a Request-table verification node: the IF key's value is neither a non-empty String nor a Map (JSONRequest). IF is a conditional guard (expression string or nested condition object); any other JSON type is a configuration error.

Source

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

	 * @param <M>
	 * @param <L>
	 * @throws Exception
	 */
	public static <T, M extends Map<String, Object>, L extends List<Object>> M parse(@NotNull final RequestMethod method
			, String name, M target, M real, String database, String datasource, String namespace, String catalog, String schema
            , final IdCallback<T> idCallback, @NotNull Parser<T, M, L> parser, @NotNull OnParseCallback<T, M, L> callback) throws Exception {
		if (target == null) {
			return null;
		}

		Object _if = target.get(IF.name());
		boolean ifIsStr = _if instanceof String && StringUtil.isNotEmpty(_if, true);
		M ifObj = ifIsStr == false && _if instanceof Map<?,?> ? (M) _if : null;
//				: (_if instanceof String ? new apijson.JSONMap((String) _if, "" /* "throw new Error('')" */ ) : null);
		if (ifObj == null && _if != null && ifIsStr == false) {
//			if (_if instanceof List<?>) {
//			}
			throw new IllegalArgumentException(name + ": { " + IF.name() + ": value } 中 value 类型错误!只允许 String, JSONRequest!");
		}

		// 获取配置<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		M type = get(target, TYPE.name());
		M verify = get(target, VERIFY.name());
		M insert = get(target, INSERT.name());
		M update = get(target, UPDATE.name());
		M replace = get(target, REPLACE.name());

		String exist = StringUtil.get(getString(target, EXIST.name()));
		String unique = StringUtil.get(getString(target, UNIQUE.name()));
		String remove = StringUtil.get(getString(target, REMOVE.name()));
		String must = StringUtil.get(getString(target, MUST.name()));
		String refuse = StringUtil.get(getString(target, REFUSE.name()));

//		Object code = target.get(CODE.name());

		// 移除字段<<<<<<<<<<<<<<<<<<<

View on GitHub (pinned to 5284052872)

Solutions

  1. Set IF to a condition string ("IF":"role = ADMIN") or a nested condition object ("IF": {">": {...}})
  2. Remove the IF key entirely if no condition is needed
  3. Reload/re-cache the Request table config after fixing it

Example fix

-- before (Request table config)
{"IF": [1,2]}
-- after
{"IF": "userId = 82001"}
Defensive patterns

Strategy: validation

Validate before calling

function validateIfValue(v) {
  const ok = v == null || (typeof v === 'string' && v.trim() !== '') || (typeof v === 'object' && !Array.isArray(v));
  if (!ok) throw new Error('IF must be a non-empty String or a JSON object');
}

Type guard

const isValidIf = (v) => v == null || (typeof v === 'string' && v !== '') || (v != null && typeof v === 'object' && !Array.isArray(v));

Prevention

When it happens

Trigger: A Request table / verify config entry like "IF": 123, "IF": true, "IF": [], or "IF": "" — anything that is not a usable String or a JSON object.

Common situations: Hand-editing the Request table's JSON config and using a number/boolean for IF; copying a condition array from another tool into IF; an ORM serializing a condition object into a list.

Related errors


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