Tencent/APIJSON · error · UnsupportedDataTypeException

批量新增/修改失败!{}/{}:value 中value不合法!类型必须是 OBJECT ,结构为 {} !

Error message

批量新增/修改失败!{}/{}:value 中value不合法!类型必须是 OBJECT ,结构为 {} !

What it means

During a batch add/update (key:[] with an array of objects) each element is fetched with JSON.get(valueArray, i); if that returns null or throws (element is not a JSON object), UnsupportedDataTypeException is thrown. The message states the exact key and index whose value must be an OBJECT with structure {}.

Source

Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java:825

        cfg.setTable(childKey); // Request 表 structure 中配置 "ALLOW_PARTIAL_UPDATE_FAILED": "Table[],key[],key:alias[]" 自动配置
        boolean allowPartialFailed = cfg.allowPartialUpdateFailed();
        L failedIds = allowPartialFailed ? JSON.createJSONArray() : null;

        int firstFailIndex = -1;
        M firstFailReq = null;
        Throwable firstFailThrow = null;
		for (int i = 0; i < valueArray.size(); i++) { //只要有一条失败,则抛出异常,全部失败
			//TODO 改成一条多 VALUES 的 SQL 性能更高,报错也更会更好处理,更人性化
			M item;
			try {
				item = JSON.get(valueArray, i);
                if (item == null) {
                    throw new NullPointerException();
                }
			}
			catch (Exception e) {
				throw new UnsupportedDataTypeException(
                        "批量新增/修改失败!" + key + "/" + i + ":value 中value不合法!类型必须是 OBJECT ,结构为 {} !"
                );
			}

            Object id = item.get(idKey);
			M req = JSON.createJSONObject(childKey, item);

            M result = null;
            try {
                if (isNeedVerifyContent) {
                    req = parser.parseCorrectRequest(method, childKey, version, "", req, maxUpdateCount, parser);
                }
                //parser.getMaxSQLCount() ? 可能恶意调用接口,把数据库拖死
                result = (M) onChildParse(0, "" + i, req, null);
            }
            catch (Exception e) {
                if (allowPartialFailed == false) {
                    throw e;

View on GitHub (pinned to 5284052872)

Solutions

  1. Inspect the reported key/i in the message and fix that array element to be a plain JSON object {}
  2. Validate the whole array client-side: every element must be a non-null object before sending
  3. If you meant a nested structure, flatten it — the batch API only accepts one level of objects
  4. Check for accidental double-serialization (JSON.stringify applied twice) which yields string elements

Example fix

// before
{"Moment:[]":[{"content":"a"}, ""]}
// after
{"Moment:[]":[{"content":"a"}, {"content":""}]}
Defensive patterns

Strategy: type-guard

Validate before calling

List<Object> arr = (List<Object>) raw.get("key");
for (int i = 0; i < arr.size(); i++) {
  if (!(arr.get(i) instanceof Map)) throw new IllegalArgumentException("item " + i + " must be an object");
}

Type guard

boolean allBatchItemsAreObjects(List<?> arr) {
  return arr != null && arr.stream().allMatch(x -> x instanceof Map && x != null);
}

Try / catch

catch (UnsupportedDataTypeException e) { if (e.getMessage().contains("批量新增/修改失败")) { logBadItem(e.getMessage()); fixPayload(); } else throw e; }

Prevention

When it happens

Trigger: A batch POST/PUT where the value array contains a non-object element, e.g. "key":[{...}, "string", 123, null, [{...}]]. Also triggered when JSON.get fails to convert an element to the map type, or the element is JSON null.

Common situations: Client serializes a list where one item is a scalar or nested array; hand-built JSON strings with a trailing comma producing a null element; mixing single-object and batch formats (wrapping an object inside an array of arrays); version upgrades where an API previously accepted loose values.

Related errors


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