Cannot construct instance of `***.***.ArrayList` (although at least one Creator ...
错误信息
status_code=400, JSON parse error: Cannot construct instance of `***.***.ArrayList` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('</block>'); nested exception is ***.***.***.***.***.MismatchedInputException: Cannot construct instance of `***.***.ArrayList` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('</block>')
at [Source: (***.***.***.StreamUtils$NonClosingInputStream); line: 1, column: 104892] (through reference chain: ***.***.***.***.***.***.***.ChatCompletionRequest["stop"])
AI 解决方案
🔍 报错分析
1. 🌐 错误翻译
原文:status_code=400, JSON parse error: Cannot construct instance of `***.***.ArrayList` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('</block>'); nested exception is ***.***.***.***.***.***.MismatchedInputException: Cannot construct instance of `***.***.ArrayList` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('</block>') at [Source: (***.***.***.StreamUtils$NonClosingInputStream); line: 1, column: 104892] (through reference chain: ***.***.***.***.***.***.***.ChatCompletionRequest["stop"])
译文:状态码=400,JSON解析错误:无法构造`***.***.ArrayList`的实例(尽管至少存在一个Creator):没有接受String参数的构造函数/工厂方法来从String值('</block>')反序列化;嵌套异常为***.***.***.***.***.***.MismatchedInputException:无法构造`***.***.ArrayList`的实例(尽管至少存在一个Creator):没有接受String参数的构造函数/工厂方法来从String值('</block>')反序列化,位于[源:(***.***.***.StreamUtils$NonClosingInputStream);行:1,列:104892](通过引用链:***.***.***.***.***.***.***.ChatCompletionRequest["stop"])
2. 🎯 原因分析
根本原因:JSON反序列化时类型不匹配。服务端期望
stop字段是一个ArrayList集合类型,但实际接收到的是字符串值</block>,Jackson无法将字符串直接转换为目标集合类型。具体位置:错误发生在解析ChatCompletionRequest对象的stop字段时,JSON数据中该位置是字符串,而目标类型是ArrayList。
3. 💡 解决方案
需要检查JSON请求数据和对应的Java类定义,确保类型匹配。以下提供两种常见修复方案:
方案一:修正JSON请求数据(如果stop本应是集合)
{
"stop": ["</block>"],
// 其他字段...
}
将字符串包装成数组。
方案二:修改Java类定义(如果stop本应是字符串)
// 错误定义:stop是ArrayList
private ArrayList<String> stop;
// 修正为:stop是String
private String stop;
方案三:若需兼容两种类型,添加@JsonFormat注解
import com.fasterxml.jackson.annotation.JsonFormat;
public class ChatCompletionRequest {
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
private ArrayList<String> stop;
// getter/setter等
}