在Spring控制器中进行JSR-303验证并获取@JsonProperty名称 [英] JSR-303 validation in Spring controller and getting @JsonProperty name

查看:220
本文介绍了在Spring控制器中进行JSR-303验证并获取@JsonProperty名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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).

推荐答案

现在可以使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆