{"record":{"id":"8439e12bfee23e31","repo":"Tencent/APIJSON","slug":"json-8439e1","errorCode":null,"errorMessage":"JSON格式不合法！","messagePattern":"JSON格式不合法！","errorType":"validation","errorClass":"UnsupportedEncodingException","httpStatus":null,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractParser.java","lineNumber":487,"sourceCode":"\t@Override\n\tpublic String parse(M request) {\n\t\treturn JSON.toJSONString(parseResponse(request));\n\t}\n\n\t/**解析请求json并获取对应结果\n\t * @param request 先parseRequest中URLDecoder.decode(request, UTF_8);再parseResponse(getCorrectRequest(...))\n\t * @return parseResponse(requestObject);\n\t */\n\t@NotNull\n\t@Override\n\tpublic M parseResponse(String request) {\n\t\tLog.d(TAG, \"\\n\\n\\n\\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\n\"\n\t\t\t\t+ requestMethod + \"/parseResponse  request = \\n\" + request + \"\\n\\n\");\n\n\t\ttry {\n\t\t\trequestObject = JSON.parseObject(request);\n\t\t\tif (requestObject == null) {\n\t\t\t\tthrow new UnsupportedEncodingException(\"JSON格式不合法！\");\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\treturn newErrorResult(e, isRoot);\n\t\t}\n\n\t\treturn parseResponse(requestObject);\n\t}\n\n\tprivate int queryDepth;\n\tprivate long executedSQLDuration;\n\n\t/**解析请求json并获取对应结果\n\t * @param request\n\t * @return requestObject\n\t */\n\t@NotNull\n\t@Override\n\tpublic M parseResponse(M request) {","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java#L469-L505","documentation":"In parseResponse(String), JSON.parseObject returning null (e.g. input is \"null\", empty after trim, or a bare scalar) triggers UnsupportedEncodingException('JSON格式不合法！'). Unlike parseRequest it is caught internally and converted into an error result object rather than propagating.","triggerScenarios":"Calling parseResponse with the literal string \"null\", an empty string, whitespace, or a top-level non-object token like \"123\"/\"\\\"text\\\"\" — parseObject succeeds but yields null for an object expectation.","commonSituations":"Upstream service or queue returns an empty body on error and the client forwards it directly; string concatenation defaults produce \"null\" from a Java null; misconfigured mock server returning plain text; retry logic passing a previously-consumed stream rendered as null.","solutions":["Check the input string is non-empty and starts with '{' before calling parseResponse","Fix the upstream producer that emitted null/empty where a JSON object was promised","Inspect the returned error result's msg — it reflects this exact parse failure point","Add a client-side guard: if body == null || body.trim().isEmpty() or equals \"null\", raise a transport error instead"],"exampleFix":"// before\nparser.parseResponse(readBodySilently(httpRequest)); // may be \"\" or \"null\"\n// after\nString body = readBody(httpRequest);\nif (body == null || body.trim().isEmpty() || \"null\".equals(body.trim())) throw new IOException(\"empty response\");\nparser.parseResponse(body);","handlingStrategy":"type-guard","validationCode":"String b = body == null ? null : body.trim();\nif (b == null || b.isEmpty() || \"null\".equals(b)) return errorResult(\"empty/non-object response\");","typeGuard":"boolean isNonEmptyJsonObject(String s) {\n  String t = s == null ? \"\" : s.trim();\n  return t.startsWith(\"{\") && t.endsWith(\"}\");\n}","tryCatchPattern":null,"preventionTips":["Treat empty/null upstream bodies as transport errors before parsing","Never forward readBody() results unchecked from HTTP clients that return \"null\" strings","Assert response shape in integration tests, not just status codes"],"tags":["apijson","json","parse","empty-body"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}