{"record":{"id":"78c768daa46e4b8a","repo":"Tencent/APIJSON","slug":"key-value-value-array","errorCode":null,"errorMessage":"{key}:value 的 value 不合法！类型必须是 ARRAY ，结构为 [] !","messagePattern":"(.+?):value 的 value 不合法！类型必须是 ARRAY ，结构为 \\[\\] !","errorType":"validation","errorClass":"UnsupportedDataTypeException","httpStatus":400,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java","lineNumber":1024,"sourceCode":"\t\t\t\t}\n\t\t\t\tif (rvalue != null && trimKeyList != null && trimKeyList.contains(key)) {\n\t\t\t\t\trvalue = StringUtil.trim(rvalue);\n\t\t\t\t}\n\n\t\t\t\tif (callback.onParse(key, tvalue, rvalue) == false) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (tvalue instanceof Map<?, ?>) { // JSONRequest，往下一级提取\n\t\t\t\t\tif (rvalue != null && rvalue instanceof Map<?, ?> == false) {\n\t\t\t\t\t\tthrow new UnsupportedDataTypeException(key + \":value 的 value 不合法！类型必须是 OBJECT ，结构为 {} !\");\n\t\t\t\t\t}\n\t\t\t\t\ttvalue = callback.onParseJSONObject(key, (M) tvalue, (M) rvalue);\n\n\t\t\t\t\tobjKeySet.add(key);\n\t\t\t\t} else if (tvalue instanceof List<?>) { // L\n\t\t\t\t\tif (rvalue != null && rvalue instanceof List<?> == false) {\n\t\t\t\t\t\tthrow new UnsupportedDataTypeException(key + \":value 的 value 不合法！类型必须是 ARRAY ，结构为 [] !\");\n\t\t\t\t\t}\n\t\t\t\t\ttvalue = callback.onParseJSONArray(key, (L) tvalue, (L) rvalue);\n\n\t\t\t\t\tif ((method == POST || method == PUT) && isArrayKey(key)) {\n\t\t\t\t\t\tobjKeySet.add(key);\n\t\t\t\t\t}\n\t\t\t\t} else { // 其它Object\n\t\t\t\t\ttvalue = callback.onParseObject(key, tvalue, rvalue);\n\t\t\t\t}\n\n\t\t\t\tif (tvalue != null) { // 可以在target中加上一些不需要客户端传的键值对\n\t\t\t\t\treal.put(key, tvalue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\t// 解析内容>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>","sourceCodeStart":1006,"sourceCodeEnd":1042,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java#L1006-L1042","documentation":"Thrown during template-value merge in verify: the target (Request-table template) declares a key whose value is an ARRAY ([]), but the client sent a non-array (scalar or object). The request must match the template's shape.","triggerScenarios":"Template has \"User\":{\"tag\":[]} but the client sends {\"User\":{\"tag\":\"a\"}} or {\"User\":{\"tag\":{\"0\":\"a\"}}} — rvalue is not a List while tvalue is.","commonSituations":"Client JSON-encodes an array into a string; a form encoder turns [] into an object with numeric keys; template authored with [] as placeholder while clients send single values.","solutions":["Send the value as a JSON array: {\"tag\":[\"a\"]}","Fix client serialization so arrays stay arrays (correct Content-Type: application/json)","If scalars are intended, update the template value to a scalar"],"exampleFix":"// before\n{\"User\":{\"tag\":\"a\"}}\n// after\n{\"User\":{\"tag\":[\"a\"]}}","handlingStrategy":"type-guard","validationCode":"function assertShape(value, template) {\n  for (const k of Object.keys(template)) {\n    const t = template[k], v = value[k];\n    if (v != null && Array.isArray(t) && !Array.isArray(v)) {\n      throw new TypeError(`${k} must be an array per template`);\n    }\n  }\n}","typeGuard":"const isArrayOrNull = (v) => v == null || Array.isArray(v);","tryCatchPattern":null,"preventionTips":["Wrap single values in arrays when the template declares []","Avoid form-style encoders that convert arrays to objects; send real JSON"],"tags":["apijson","type-mismatch","structure","array"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}