#Crud Rest api spring, validate String only numbers,

8 messages · Page 1 of 1 (latest)

unique mauve
#

I have entity called contact with private Long id, private ContactType contacttype; (enum) and private String contactvalue; i have two types of enum (phonenumber and email), so i want to validate when person using phonenumber enumarated String contactvalue must be numbers only and if person uses email enum then he can use any characters

sleek axleBOT
#

This post has been reserved for your question.

Hey @unique mauve! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

unique mauve
#

request dto

wintry axle
#

One way would be to use inheritance and Jackson's polymorphic deserialization to create a PhoneNumber DTO and an Email DTO, each of which defines its own validated version of value

#

you can google "jackson polymorphic deserialization" and there are some good articles I think