{"record":{"id":"ebf067c393337c1e","repo":"Tencent/APIJSON","slug":"put-string","errorCode":null,"errorMessage":"PUT {}, {}/{} 必须为 String 类型 ！","messagePattern":"PUT (.+?), (.+?)/(.+?) 必须为 String 类型 ！","errorType":"validation","errorClass":"ConflictException","httpStatus":null,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java","lineNumber":771,"sourceCode":"\t\t\t\t\tif (targetArray.contains(obj)) {\n\t\t\t\t\t\tthrow new ConflictException(\"PUT \" + path + \", \" + key + \"/\" + i + \" 已存在！\");\n\t\t\t\t\t}\n\t\t\t\t\ttargetArray.add(obj);\n\t\t\t\t} else {\n\t\t\t\t\tif (obj != null && obj instanceof Map == false) {\n\t\t\t\t\t\tthrow new ConflictException(\"PUT \" + path + \", \" + key + \"/\" + i + \" 必须为 JSONRequest {} ！\");\n\t\t\t\t\t}\n\t\t\t\t\ttargetObj.putAll((Map) obj);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (targetArray != null) {\n\t\t\t\t\tif (targetArray.contains(obj) == false) {\n\t\t\t\t\t\tthrow new NullPointerException(\"PUT \" + path + \", \" + key + \"/\" + i + \" 不存在！\");\n\t\t\t\t\t}\n\t\t\t\t\ttargetArray.remove(obj);\n\t\t\t\t} else {\n\t\t\t\t\tif (obj instanceof String == false) {\n\t\t\t\t\t\tthrow new ConflictException(\"PUT \" + path + \", \" + key + \"/\" + i + \" 必须为 String 类型 ！\");\n\t\t\t\t\t}\n\t\t\t\t\tif (targetObj.containsKey(obj) == false) {\n\t\t\t\t\t\tthrow new NullPointerException(\"PUT \" + path + \", \" + key + \"/\" + i + \" 不存在！\");\n\t\t\t\t\t}\n\t\t\t\t\ttargetObj.remove(obj);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t//add all 或 remove all >>>>>>>>>>>>>>>>>>>>>>>>>\n\n\t\t//PUT <<<<<<<<<<<<<<<<<<<<<<<<<\n\t\tsqlRequest.put(realKey, targetArray != null ? targetArray : JSON.toJSONString(targetObj)); // FIXME, SerializerFeature.WriteMapNullValue));\n\t\t//PUT >>>>>>>>>>>>>>>>>>>>>>>>>\n\n\t}\n\n","sourceCodeStart":753,"sourceCodeEnd":789,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java#L753-L789","documentation":"When 'key-' targets a JSONObject-valued column, elements of the argument array name the keys to delete from that object, so each element must be a String. A non-String element (number, boolean, object, array) triggers ConflictException '必须为 String 类型 ！' with the key and index, since only string keys can be removed from a JSON object.","triggerScenarios":"PUT { \"settings-\": [1] } or { \"settings-\": [ { \"theme\": \"dark\" } ] } against a JSONObject column — correct form is \"settings-\": [\"theme\"].","commonSituations":"Using object/array elements for removal like for addition (key+ takes objects, key- takes key names); numeric keys serialized as JSON numbers instead of strings.","solutions":["For object columns use string key names: \"settings-\": [\"theme\", \"language\"].","Remember the asymmetry: 'key+': [{'k': v}] merges objects; 'key-': ['k'] removes keys.","Stringify numeric-looking keys before sending."],"exampleFix":"// before\n{ \"User\": { \"id\": 1, \"settings-\": [ { \"theme\": \"dark\" } ] } }\n// after\n{ \"User\": { \"id\": 1, \"settings-\": [ \"theme\" ] } }","handlingStrategy":"type-guard","validationCode":"Object current = fetchColumnValue(tableName, id, key);\nif (current instanceof Map) {\n  for (Object o : payload) if (!(o instanceof String)) throw new IllegalArgumentException(key + \"- elements must be String key names for object columns\");\n}","typeGuard":"function removalPayloadValid(current: unknown, payload: unknown[]): boolean {\n  const isObj = current !== null && typeof current === 'object' && !Array.isArray(current);\n  return payload.every(p => !isObj || typeof p === 'string');\n}","tryCatchPattern":null,"preventionTips":["Remember the asymmetry: key+ merges objects, key- removes String key names.","Stringify numeric-looking keys before adding them to a key- array.","Validate payload element types against the column's JSON kind before sending."],"tags":["apijson","put","json-object","type-check","request-syntax"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}