{"record":{"id":"81a23caf1270ae45","repo":"Tencent/APIJSON","slug":"value-value-object","errorCode":null,"errorMessage":"批量新增/修改失败！{}/{}:value 中value不合法！类型必须是 OBJECT ，结构为 {} !","messagePattern":"批量新增/修改失败！(.+?)/(.+?):value 中value不合法！类型必须是 OBJECT ，结构为 (.+?) !","errorType":"validation","errorClass":"UnsupportedDataTypeException","httpStatus":null,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java","lineNumber":825,"sourceCode":"\n        cfg.setTable(childKey); // Request 表 structure 中配置 \"ALLOW_PARTIAL_UPDATE_FAILED\": \"Table[],key[],key:alias[]\" 自动配置\n        boolean allowPartialFailed = cfg.allowPartialUpdateFailed();\n        L failedIds = allowPartialFailed ? JSON.createJSONArray() : null;\n\n        int firstFailIndex = -1;\n        M firstFailReq = null;\n        Throwable firstFailThrow = null;\n\t\tfor (int i = 0; i < valueArray.size(); i++) { //只要有一条失败，则抛出异常，全部失败\n\t\t\t//TODO 改成一条多 VALUES 的 SQL 性能更高，报错也更会更好处理，更人性化\n\t\t\tM item;\n\t\t\ttry {\n\t\t\t\titem = JSON.get(valueArray, i);\n                if (item == null) {\n                    throw new NullPointerException();\n                }\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new UnsupportedDataTypeException(\n                        \"批量新增/修改失败！\" + key + \"/\" + i + \":value 中value不合法！类型必须是 OBJECT ，结构为 {} !\"\n                );\n\t\t\t}\n\n            Object id = item.get(idKey);\n\t\t\tM req = JSON.createJSONObject(childKey, item);\n\n            M result = null;\n            try {\n                if (isNeedVerifyContent) {\n                    req = parser.parseCorrectRequest(method, childKey, version, \"\", req, maxUpdateCount, parser);\n                }\n                //parser.getMaxSQLCount() ? 可能恶意调用接口，把数据库拖死\n                result = (M) onChildParse(0, \"\" + i, req, null);\n            }\n            catch (Exception e) {\n                if (allowPartialFailed == false) {\n                    throw e;","sourceCodeStart":807,"sourceCodeEnd":843,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java#L807-L843","documentation":"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 {}.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the reported key/i in the message and fix that array element to be a plain JSON object {}","Validate the whole array client-side: every element must be a non-null object before sending","If you meant a nested structure, flatten it — the batch API only accepts one level of objects","Check for accidental double-serialization (JSON.stringify applied twice) which yields string elements"],"exampleFix":"// before\n{\"Moment:[]\":[{\"content\":\"a\"}, \"\"]}\n// after\n{\"Moment:[]\":[{\"content\":\"a\"}, {\"content\":\"\"}]}","handlingStrategy":"type-guard","validationCode":"List<Object> arr = (List<Object>) raw.get(\"key\");\nfor (int i = 0; i < arr.size(); i++) {\n  if (!(arr.get(i) instanceof Map)) throw new IllegalArgumentException(\"item \" + i + \" must be an object\");\n}","typeGuard":"boolean allBatchItemsAreObjects(List<?> arr) {\n  return arr != null && arr.stream().allMatch(x -> x instanceof Map && x != null);\n}","tryCatchPattern":"catch (UnsupportedDataTypeException e) { if (e.getMessage().contains(\"批量新增/修改失败\")) { logBadItem(e.getMessage()); fixPayload(); } else throw e; }","preventionTips":["Always serialize batch payloads with a JSON library from typed DTO lists","Assert every element is an object in a unit test of the payload builder","Never splice scalars or nested arrays into a batch value array"],"tags":["apijson","batch","unsupported-type","validation","array"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}