{"record":{"id":"a327e798cf797d9b","repo":"alibaba/nacos","slug":"json-param-invalid","errorCode":null,"errorMessage":"json param invalid.","messagePattern":"json param invalid\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java","lineNumber":323,"sourceCode":"            try {\n                if (SwitchEntry.HTTP_HEALTH_PARAMS.equals(entry)) {\n                    SwitchDomain.HttpHealthParams httpHealthParams =\n                        JacksonUtils.toObj(value, SwitchDomain.HttpHealthParams.class);\n                    tempSwitchDomain.setHttpHealthParams(httpHealthParams);\n                    validateHealthParams(httpHealthParams);\n                }\n                if (SwitchEntry.TCP_HEALTH_PARAMS.equals(entry)) {\n                    SwitchDomain.TcpHealthParams tcpHealthParams =\n                        JacksonUtils.toObj(value, SwitchDomain.TcpHealthParams.class);\n                    tempSwitchDomain.setTcpHealthParams(tcpHealthParams);\n                    validateHealthParams(tcpHealthParams);\n                }\n                if (SwitchEntry.MYSQL_HEALTH_PARAMS.equals(entry)) {\n                    tempSwitchDomain.setMysqlHealthParams(\n                        JacksonUtils.toObj(value, SwitchDomain.MysqlHealthParams.class));\n                }\n            } catch (NacosDeserializationException e) {\n                throw new IllegalArgumentException(\"json param invalid.\");\n            }\n            \n            if (debug) {\n                update(tempSwitchDomain);\n            } else {\n                updateWithConsistency(tempSwitchDomain);\n            }\n            \n        } finally {\n            this.requestLock.unlock();\n        }\n        \n    }\n    \n    /**\n     * Update switch information from new switch domain.\n     *\n     * @param newSwitchDomain new switch domain","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java#L305-L341","documentation":"Thrown when entry is httpHealthParams, tcpHealthParams, or mysqlHealthParams and Jackson deserialization (JacksonUtils.toObj) fails with a NacosDeserializationException. The value must be a valid JSON object matching the HealthParams structure (with min, max, factor fields). Note: only http and tcp params are validated post-deserialization; mysql params are not.","triggerScenarios":"PUT /v3/admin/ns/operator/switches with entry=httpHealthParams and a malformed JSON value, e.g. value='{', value='{min:}', value='not json'.","commonSituations":"Passing a plain string or truncated JSON, using single quotes instead of double quotes, or missing required fields.","solutions":["Provide a complete JSON object with double-quoted keys: {\"min\":500,\"max\":5000,\"factor\":0.85}.","Validate the JSON with a parser before sending.","For http/tcp params, also ensure min >= 500, max >= 3000, and 0 <= factor <= 1."],"exampleFix":"// before\nPUT /v3/admin/ns/operator/switches?entry=httpHealthParams&value={\n// after\nPUT /v3/admin/ns/operator/switches?entry=httpHealthParams&value={\"min\":500,\"max\":5000,\"factor\":0.85}","handlingStrategy":"validation","validationCode":"try {\n    objectMapper.readTree(value); // validate JSON parseability\n} catch (Exception e) {\n    throw new IllegalArgumentException(\"Health params value is not valid JSON\");\n}","typeGuard":"function isValidHealthParamsJson(value: string): boolean {\n  try {\n    const obj = JSON.parse(value);\n    return typeof obj === 'object' && obj !== null;\n  } catch { return false; }\n}","tryCatchPattern":"try {\n  operatorV2Impl.updateSwitch(entry, value, debug);\n} catch (NacosApiException e) {\n  if (e.getMessage().contains(\"json param invalid\")) {\n    // re-serialize the health params object to proper JSON\n  }\n}","preventionTips":["Serialize the HealthParams object with a JSON serializer, do not hand-write JSON.","Use double quotes for keys and string values."],"tags":["naming","switch","validation","json","health-params"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}