{"record":{"id":"832698cca1c8a91f","repo":"apache/dubbo","slug":"value-s-for-key-s-in-s-is-not-object","errorCode":null,"errorMessage":"value '%s' for key '%s' in '%s' is not object","messagePattern":"value '(.+?)' for key '(.+?)' in '(.+?)' is not object","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java","lineNumber":104,"sourceCode":"        }\n        return checkStringList(list);\n    }\n\n    /**\n     * Gets an object from an object for the given key.  If the key is not present, this returns null.\n     * If the value is not a Map, throws an exception.\n     */\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public Map<String, ?> getObject(Map<String, ?> obj, String key) {\n        assert obj != null;\n        assert key != null;\n        if (!obj.containsKey(key)) {\n            return null;\n        }\n        Object value = obj.get(key);\n        if (!(value instanceof Map)) {\n            throw new ClassCastException(\n                    String.format(\"value '%s' for key '%s' in '%s' is not object\", value, key, obj));\n        }\n        return (Map<String, ?>) value;\n    }\n\n    /**\n     * Gets a number from an object for the given key.  If the key is not present, this returns null.\n     * If the value does not represent a double, throws an exception.\n     */\n    @Override\n    public Double getNumberAsDouble(Map<String, ?> obj, String key) {\n        assert obj != null;\n        assert key != null;\n        if (!obj.containsKey(key)) {\n            return null;\n        }\n        Object value = obj.get(key);\n        if (value instanceof Double) {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java#L86-L122","documentation":"Thrown by AbstractJsonUtilImpl.getObject(Map,String) when obj contains key but its value is not a java.util.Map. getObject returns null for an absent key; the exception fires only when the key is present but the value is a scalar, list, or other non-map type. It is a ClassCastException signalling that the JSON value is not a JSON object where one was expected.","triggerScenarios":"jsonUtil.getObject(obj, key) where obj.get(key) exists and is a String/Number/Boolean/List (i.e. a JSON scalar or array) rather than a JSON object. Example JSON {\"user\": \"alice\"} with getObject(obj, \"user\").","commonSituations":"Field that was an object got flattened to a string/id by an API change; payload represents a one-of where the field is sometimes an object and sometimes a reference string; wrong key used against a schema where the field is an array; downstream returning an error string instead of an object.","solutions":["Inspect obj.get(key)'s runtime type and reconcile with the expected schema.","If the field can be a string-id or a full object, branch on instanceof Map before calling getObject.","Normalize the payload upstream so the field is always an object.","Catch ClassCastException and surface the offending key for triage."],"exampleFix":"// before\nMap<String,?> user = jsonUtil.getObject(obj, \"user\");\n// after - tolerate id-or-object\nObject raw = obj.get(\"user\");\nMap<String,?> user = raw instanceof Map ? (Map<String,?>) raw : null;","handlingStrategy":"type-guard","validationCode":"Object raw = obj.get(key);\nif (raw != null && !(raw instanceof Map)) {\n    // field present but not an object\n    return null;\n}\nreturn jsonUtil.getObject(obj, key);","typeGuard":"private static boolean isObjectOrNull(Object value) {\n    return value == null || value instanceof Map;\n}","tryCatchPattern":"try {\n    return jsonUtil.getObject(obj, key);\n} catch (ClassCastException e) {\n    log.warn(\"expected object at key={}, got value={}\", key, obj.get(key));\n    return null;\n}","preventionTips":["Branch on instanceof Map before calling getObject for fields that may be string-ids or objects.","Validate the JSON schema for fields read with getObject.","Reconcile with the producer when an object field is flattened to a scalar."],"tags":["json","type-mismatch","classcast","jsonutil","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}