fluent-validator icon indicating copy to clipboard operation
fluent-validator copied to clipboard

为什么ValidationError的ErrorCode必须是Integer?

Open kaixlin opened this issue 6 years ago • 5 comments

因为我们项目中使用的ErrorCode是用String数据类型,所以String数据类型感觉会更通用一些吧。

kaixlin avatar Dec 02 '18 05:12 kaixlin

嗯呢,ErrorCode用string或者int这个没有准则吧,只是这个类库选择了int,code一般都会有错误码,数字达意了。

neoremind avatar Dec 16 '18 09:12 neoremind

Just extends ValidationError like I did. Example:

public class FluentValidationError extends ValidationError {
	private String errorKey;

	public String getErrorKey() {
		return errorKey;
	}

	public FluentValidationError setErrorKey(String errorKey) {
		this.errorKey = errorKey;
		return this;
	}
}

tiagocpeixoto avatar Dec 17 '18 16:12 tiagocpeixoto

@tiagocpeixoto great catch!

neoremind avatar Dec 18 '18 03:12 neoremind

也遇到了相同的问题,现在项目定义的 ErrorCode 是 string类型

dongzl avatar Dec 11 '21 05:12 dongzl

项目初始考虑欠佳,可以通过上面 tiagocpeixoto 的扩展方式workaround支持下。

neoremind avatar Dec 15 '21 16:12 neoremind