Tencent/APIJSON · error · UnsupportedDataTypeException

{}.id 类型错误,类型必须是 Long/String!

Error message

{}.id 类型错误,类型必须是 Long/String!

What it means

In the CONTACT-role id loop, a supplied id must be a Number or a String; anything else (JSONObject, Boolean, null-ish nested structure, List) throws UnsupportedDataTypeException with the message '<table>.id 类型错误,类型必须是 Long/String!'. Note ids that are literally null are skipped by the continue above — the error is strictly about wrong JSON types.

Source

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

				for (Object id : requestIdArray) {
					if (id == null) {
						continue;
					}

					if (id instanceof Number) { // 不能准确地判断 Long,可能是 Integer
						if (((Number) id).longValue() <= 0 || list.contains(Long.valueOf("" + id)) == false) { // Integer等转为 Long 才能正确判断,强转崩溃
							throw new IllegalAccessException(visitorIdKey + " = " + id + " 的 " + table
									+ " 不允许 " + role + " 用户的 " + method.name() + " 请求!");
						}
					}
					else if (id instanceof String) {
						if (StringUtil.isEmpty(id) || list.contains(id) == false) {
							throw new IllegalAccessException(visitorIdKey + " = " + id + " 的 " + table
									+ " 不允许 " + role + " 用户的 " + method.name() + " 请求!");
						}
					}
					else {
						throw new UnsupportedDataTypeException(table + ".id 类型错误,类型必须是 Long/String!");
					}
				}
			}
			break;
		case OWNER:
			if (config.getMethod() == POST) {
				List<String> c = config.getColumn();
				List<List<Object>> ovs = config.getValues();
				if ( (c == null || c.isEmpty()) || (ovs == null || ovs.isEmpty()) ) {
					throw new IllegalArgumentException("POST 请求必须在Table内设置要保存的 key:value !");
				}

				int index = c.indexOf(visitorIdKey);
				if (index >= 0) {
					Object oid;
					for (List<Object> ovl : ovs) {
						oid = ovl == null || index >= ovl.size() ? null : ovl.get(index);
						if (oid == null || StringUtil.get(oid).equals("" + visitorId) == false) {

View on GitHub (pinned to 5284052872)

Solutions

  1. Change the request so the visitor id key holds a scalar Long or String value (or an array via the documented key{} form).
  2. If a range/match expression is needed, use APIJSON's operator keys (e.g. userId{}) instead of overloading the plain key.
  3. Add client-side schema validation that the id field is number|string before sending.

Example fix

// before
{ "User": { "userId": { "$regex": "^12" }, "role": "CONTACT" } }

// after
{ "User": { "userId": 123, "role": "CONTACT" } }
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(idValue instanceof Number) && !(idValue instanceof String)) {
    clientError("id must be Long or String, got " + idValue.getClass().getSimpleName());
}

Type guard

boolean isScalarId(Object v) { return v == null || v instanceof Number || v instanceof String; }

Try / catch

catch (UnsupportedDataTypeException e) { 400 bad request; echo the expected types; no retry.

Prevention

When it happens

Trigger: A CONTACT-role request passes an object or array as the id condition value, e.g. "userId": {"$regex":"..."} or "userId": [1,2] directly under the visitor id key, or a boolean; the else branch of the instanceof chain fires.

Common situations: Client builds dynamic where-values and accidentally nests an object where a scalar belongs; APIJSON operators (key{}, key$) placed under the plain key name; hand-crafted JSON tests using wrong literal types.

Related errors


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