alibaba/spring-ai-alibaba · warning

解析默认参数失败: {}

Error message

解析默认参数失败: {}

What it means

ChatClientFactoryDelegate.mergeParameters parses the model config's defaultParameters JSON string into a Map and merges it under the caller-supplied user parameters. If the JSON cannot be parsed into Map.class, it warns with the raw string and continues with only the user parameters.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/client/ChatClientFactoryDelegate.java:140

     *
     * @param userParameters 用户传入的参数
     * @return 合并后的参数
     */
    private Map<String, Object> mergeParameters(ModelConfigDO config, Map<String, Object> userParameters) {
        Map<String, Object> mergedParameters = new HashMap<>();
        
        // 首先添加默认参数
        if (StringUtils.hasText(config.getDefaultParameters())) {
            try {
                @SuppressWarnings("unchecked")
                Map<String, Object> defaultParams = objectMapper.readValue(
                        config.getDefaultParameters(),
                        Map.class
                );
                mergedParameters.putAll(defaultParams);
                log.debug("加载默认参数: {}", defaultParams);
            } catch (Exception e) {
                log.warn("解析默认参数失败: {}", config.getDefaultParameters(), e);
            }
        }
        
        // 然后添加用户参数(覆盖默认参数)
        if (userParameters != null) {
            mergedParameters.putAll(userParameters);
            log.debug("用户参数: {}", userParameters);
        }
        
        log.debug("合并后的参数: {}", mergedParameters);
        return mergedParameters;
    }
}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Fix defaultParameters in the model config to be a valid JSON object, e.g. {"temperature":0.7}
  2. Validate the JSON in the UI/API before saving model configs
  3. Make mergeParameters throw or return an error for invalid JSON instead of silently ignoring defaults, so bad configs surface immediately

Example fix

// before
defaultParameters: "{'temperature':0.7}"
// after
defaultParameters: "{\"temperature\":0.7}"
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidJsonObject(String s) {
    if (s == null || s.isBlank()) return true; // optional field
    try { new ObjectMapper().readValue(s, Map.class); return true; } catch (Exception e) { return false; }
}
// reject model configs whose defaultParameters fails isValidJsonObject

Try / catch

try { client = delegate.createChatClient(config); }
catch (Exception e) { log.warn("falling back to params without defaults: {}", e.getMessage()); }

Prevention

When it happens

Trigger: mergedParameters -> mergeParameters with config.getDefaultParameters() that is malformed JSON, a JSON array/string/scalar instead of an object, or null-garbage from a prior save.

Common situations: Admin UI saving default params with single quotes or trailing commas; another client writing a JSON array; encoding corruption; hand-edited database rows.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/f5d603e4a2289401. Report an issue: GitHub.