Skip to content
Advertisement

How to put YML value inside the @Pattern(regexp = “HELLO|WORLD”)

I want to move the “HELLO|WORLD” value to the YML file. Then call the value from YML file inside the regexp.

For example, Following is the YAML file YML FILE

JavaScript

Java class to get the YAML value

JavaScript

Java class that use regex validation

JavaScript

Instead of a string, I want to do something similar to this.

JavaScript

I have already tried the following annotation. And none of them worked

JavaScript

Is it possible to achieve this?

NOTE: I don’t really want to use a constant.

Advertisement

Answer

I don’t know of any way to use SpEL in a @Pattern annotation. There is a way to externalize regexp’s like that, but it involves creating your own validation annotation. I don’t know if that is an option for you, but something like this should work.

Annotation

JavaScript

Validator

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement