{"record":{"id":"6615c9ee9fed276a","repo":"dromara/Sa-Token","slug":"somap-value","errorCode":null,"errorMessage":"值无法转化为SoMap: ${value}","messagePattern":"值无法转化为SoMap: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sa-token-demo/sa-token-demo-oauth2/sa-token-demo-oauth2-client/src/main/java/com/pj/utils/SoMap.java","lineNumber":158,"sourceCode":"\t/** 转为Date并返回，根据格式： yyyy-MM-dd HH:mm:ss */\n\tpublic Date getDateTime(String key) {\n\t\treturn getDateByFormat(key, \"yyyy-MM-dd HH:mm:ss\");\n\t}\n\n\t/** 转为Map并返回 */\n\t@SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n\tpublic SoMap getMap(String key) {\n\t\tObject value = get(key);\n\t\tif(value == null) {\n\t\t\treturn SoMap.getSoMap();\n\t\t}\n\t\tif(value instanceof Map) {\n\t\t\treturn SoMap.getSoMap((Map)value);\n\t\t}\n\t\tif(value instanceof String) {\n\t\t\treturn SoMap.getSoMap().setJsonString((String)value);\n\t\t}\n\t\tthrow new RuntimeException(\"值无法转化为SoMap: \" + value);\n\t}\n\n\t/** 获取集合(必须原先就是个集合，否则会创建个新集合并返回) */\n\t@SuppressWarnings(\"unchecked\")\n\tpublic List<Object> getList(String key) {\n\t\tObject value = get(key);\n\t\tList<Object> list = null;\n\t\tif(value == null || value.equals(\"\")) {\n\t\t\tlist = new ArrayList<Object>();\n\t\t}\n\t\telse if(value instanceof List) {\n\t\t\tlist = (List<Object>)value;\n\t\t} else {\n\t\t\tlist = new ArrayList<Object>();\n\t\t\tlist.add(value);\n\t\t}\n\t\treturn list;\n\t}","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/dromara/Sa-Token/blob/ac2c7f6e94a78573cf0bcb932dd8b04e68fad189/sa-token-demo/sa-token-demo-oauth2/sa-token-demo-oauth2-client/src/main/java/com/pj/utils/SoMap.java#L140-L176","documentation":"Thrown by SoMap.getMap(key) when the value stored under key is neither null, nor a java.util.Map, nor a JSON String — the only three shapes the method can convert into a SoMap. It is a plain RuntimeException from the demo OAuth2 client's utility map, indicating the caller assumed a nested object where the data actually holds a scalar or a List.","triggerScenarios":"Calling soMap.getMap(\"token\") (or similar) when the parsed JSON/parameters contain a non-object under that key, e.g. an Integer, Boolean, or List. Typical in the OAuth2 client when processing an access-token response whose schema changed or whose error body put a scalar where an object was expected.","commonSituations":"The OAuth2 server returned an error JSON (e.g. {\"code\":500,\"msg\":\"...\"}) where the client unconditionally does getMap(\"data\"); or the response structure differs between sa-token versions.","solutions":["Inspect the actual value class before calling getMap: use soMap.get(key) and check instanceof Map / is JSON String.","Verify the upstream OAuth2 server response actually nests an object at that key (log the raw JSON once).","If the value arrives as a JSON string, ensure it is a JSON object literal, not an array or scalar.","Prefer the typed getModel(key, Class) accessor or check isNull(key)/getString(key) first when the schema is uncertain."],"exampleFix":"// before\nSoMap token = soMap.getMap(\"data\");\n\n// after\nObject data = soMap.get(\"data\");\nif (data == null || !(data instanceof Map || data instanceof String)) {\n    throw new IllegalStateException(\"unexpected response: \" + soMap.getString(\"msg\"));\n}\nSoMap token = soMap.getMap(\"data\");","handlingStrategy":"type-guard","validationCode":"Object v = soMap.get(key);\nif (v == null || v instanceof Map || v instanceof String) {\n    SoMap m = soMap.getMap(key); // safe\n} else {\n    // do not call getMap\n}","typeGuard":"boolean isMapLike(Object v) { return v == null || v instanceof Map || v instanceof String; }","tryCatchPattern":null,"preventionTips":["Log the raw upstream JSON once during integration to lock down the schema before adding getMap calls.","Treat error bodies (non-200 code fields) separately from success bodies before parsing nested objects."],"tags":["somap","oauth2-client","type-conversion","json"],"backgroundTag":null,"analyzedSha":"ac2c7f6e94a78573cf0bcb932dd8b04e68fad189","analyzedAt":"2026-08-14T14:36:10.271Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}