在Spring控制器中进行JSR-303验证并获取@JsonProperty名称 [英] JSR-303 validation in Spring controller and getting @JsonProperty name
问题描述
我在Spring应用程序中使用JSR-303
进行了验证,它可以根据需要运行.
I do validation with JSR-303
in my Spring app, it works as needed.
这是一个示例:
@Column(nullable = false, name = "name")
@JsonProperty("customer_name")
@NotEmpty
@Size(min = 3, max = 32)
private String name;
并且REST API客户端使用customer_name
作为发送到API芽验证字段错误的输入字段的名称org.springframework.validation.FieldError
返回name
作为该字段的名称.
And REST API clients use customer_name
as name of input field that send to API bud validation field error org.springframework.validation.FieldError
returns name
as name of the field.
是否有某种方法可以获取@JsonProperty
中指定的JSON-ish
名称?还是我必须实现自己的映射器才能将类字段名称映射到其JSON替代方案中?
Is there some way hot to get JSON-ish
name that is specified in @JsonProperty
? Or do I have to implement own mapper to map class fields name into its JSON alternative?
Edit1:将类字段重命名为与JSON名称相对应的名称是不可替代的(出于许多原因).
Renaming class fields into names that correspond to JSON names is not alternative (for many reasons).
推荐答案
现在可以使用 查看全文