{"record":{"id":"282677b522388bbf","repo":"alibaba/nacos","slug":"agentresourceext-must-contain-one-json-value","errorCode":null,"errorMessage":"AgentResourceExt must contain one JSON value","messagePattern":"AgentResourceExt must contain one JSON value","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/agent/metadata/AgentResourceExtSerializer.java","lineNumber":410,"sourceCode":"    \n    private static void rejectUnknownFields(Map<?, ?> object, Set<String> allowedFields,\n        String objectName) {\n        for (Object field : object.keySet()) {\n            if (!allowedFields.contains(field)) {\n                throw new IllegalArgumentException(\n                    \"Unknown \" + objectName + \" field: \" + field);\n            }\n        }\n    }\n    \n    private static void validateSingleJsonValue(String json) {\n        try (JsonParser parser = STRICT_JSON_FACTORY.createParser(json)) {\n            if (parser.nextToken() == null) {\n                throw new IllegalArgumentException(\"AgentResourceExt JSON must not be empty\");\n            }\n            parser.skipChildren();\n            if (parser.nextToken() != null) {\n                throw new IllegalArgumentException(\n                    \"AgentResourceExt must contain one JSON value\");\n            }\n        } catch (IOException e) {\n            throw new IllegalArgumentException(\"Invalid AgentResourceExt\", e);\n        }\n    }\n    \n    private static Set<String> unmodifiableSet(String... fields) {\n        return Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(fields)));\n    }\n}\n","sourceCodeStart":392,"sourceCodeEnd":422,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/agent/metadata/AgentResourceExtSerializer.java#L392-L422","documentation":"The ai_resource.ext JSON must contain exactly one top-level JSON value. The validateSingleJsonValue helper (line 409) throws this when trailing content remains after the first complete JSON value is parsed. This catches concatenated JSON like '{}{}' or '{} 123' which would otherwise silently parse only the first value.","triggerScenarios":"Calling AgentResourceExtSerializer.deserialize() on a string like '{...}{...}' or '{...} extra'. Also possible if a file or database column accidentally concatenates two JSON documents.","commonSituations":"Appending to a JSON file without array-wrapping; database column pollution from a bug that concatenated two writes; log or stream parsing errors that include delimiters.","solutions":["Ensure the JSON string contains exactly one top-level JSON object with no trailing content.","If storing multiple documents, use a JSON array wrapper or separate columns/rows.","Trim trailing whitespace and verify with a JSON parser before persistence."],"exampleFix":"// before\n'{\"schemaVersion\":1}{\"schemaVersion\":2}'\n// after\n'{\"schemaVersion\":1}'","handlingStrategy":"validation","validationCode":"// Use Jackson to verify single-value JSON\nObjectMapper mapper = new ObjectMapper();\nmapper.readValue(json, Object.class);\n// Jackson's readValue with default settings throws on trailing tokens","typeGuard":"public static boolean isSingleJsonValue(String json) {\n    try (JsonParser p = new JsonFactory().createParser(json)) {\n        p.nextToken();\n        p.skipChildren();\n        return p.nextToken() == null;\n    } catch (IOException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    AgentResourceExtSerializer.deserialize(json);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"one JSON value\")) {\n        // split the input and process each JSON object separately\n    }\n    throw e;\n}","preventionTips":["Never append JSON objects to the same file or column without array-wrapping.","Use atomic writes (overwrite, not append) for the ext column.","Validate with a strict JSON parser that rejects trailing content before persistence."],"tags":["validation","ai-agent","json-schema","serialization"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}