{"record":{"id":"61ff1406788a6d36","repo":"alibaba/spring-ai-alibaba","slug":"supportedparameters","errorCode":null,"errorMessage":"序列化 supportedParameters 失败","messagePattern":"序列化 supportedParameters 失败","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/FileModelConfigRepository.java","lineNumber":159,"sourceCode":"    \n    private ModelConfigDO toEntity(YamlModel m) {\n        ModelConfigDO.ModelConfigDOBuilder b = ModelConfigDO.builder().id(m.id).name(m.name)\n                .provider(m.provider.toLowerCase()).modelName(m.modelName).baseUrl(m.baseUrl)\n                .apiKey(environment != null ? environment.resolvePlaceholders(m.apiKey) : m.apiKey).status(m.status)\n                .createTime(LocalDateTime.now()).updateTime(LocalDateTime.now());\n        \n        if (m.defaultParameters != null) {\n            try {\n                b.defaultParameters(new ObjectMapper().writeValueAsString(m.defaultParameters));\n            } catch (Exception e) {\n                throw new IllegalArgumentException(\"序列化 defaultParameters 失败\", e);\n            }\n        }\n        if (m.supportedParameters != null) {\n            try {\n                b.supportedParameters(new ObjectMapper().writeValueAsString(m.supportedParameters));\n            } catch (Exception e) {\n                throw new IllegalArgumentException(\"序列化 supportedParameters 失败\", e);\n            }\n        }\n        return b.build();\n    }\n    \n    private void startWatchService() {\n        try {\n            Path dir = this.configPath.getParent();\n            if (dir == null) {\n                return;\n            }\n            WatchService ws = FileSystems.getDefault().newWatchService();\n            dir.register(ws, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE);\n            ExecutorService executor = Executors.newSingleThreadExecutor(r -> new Thread(r, \"model-config-watch\"));\n            executor.submit(() -> {\n                log.info(\"开始监听模型配置文件变更: {}\", configPath);\n                while (true) {\n                    WatchKey key = ws.take();","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/FileModelConfigRepository.java#L141-L177","documentation":"toEntity serializes m.supportedParameters to a JSON string using a fresh ObjectMapper; any writeValueAsString failure is wrapped in this IllegalArgumentException with the original exception as cause. Like defaultParameters, this field comes from user YAML and must be JSON-serializable to be stored in the entity.","triggerScenarios":"Calling toEntity (via entity()) on a model whose supportedParameters contains values Jackson cannot serialize (cyclic references, non-bean types).","commonSituations":"Anchors/aliases in YAML expanding to recursive structures; storing unusual value types (e.g., nested custom objects) in supportedParameters; refactoring the config class to hold richer objects without updating serialization.","solutions":["Read the wrapped cause to see the exact Jackson error (e.g., 'Direct self-reference leading to cycle')","Rewrite supportedParameters in the YAML as plain JSON-compatible structures (strings, numbers, lists, maps)","Eliminate recursive anchors/aliases or convert them to explicit inline values","Provide a custom serializer or ObjectMapper configuration if complex types must be supported"],"exampleFix":"// before (models.yml)\nsupportedParameters: &params\n  - temperature\n  nested: *params   # cyclic reference\n// after\nsupportedParameters:\n  - temperature\n  - top_p\n  - max_tokens","handlingStrategy":"validation","validationCode":"// Java: ensure supportedParameters is JSON-serializable before assignment\nnew ObjectMapper().writeValueAsString(model.getSupportedParameters()); // throws early if not","typeGuard":"boolean isJsonSafe(Object v) {\n    try { new ObjectMapper().writeValueAsString(v); return true; }\n    catch (JsonProcessingException e) { return false; }\n}","tryCatchPattern":"try {\n    entity = toEntity(model);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"supportedParameters\")) {\n        log.error(\"supportedParameters is not JSON-serializable\", e.getCause());\n    }\n}","preventionTips":["Model supportedParameters as List<String> or Map<String, Object> of plain values","Avoid recursive YAML aliases; inline values explicitly","Add a round-trip serialization unit test for the model config class"],"tags":["serialization","jackson","json","model-config"],"backgroundTag":"json-marshal-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}