Here’s a quickie: a small bean validation constraint annotation in Kotlin for UUIDs:

import javax.validation.Constraint
import javax.validation.Payload
import javax.validation.constraints.NotBlank
import javax.validation.constraints.Pattern
import kotlin.reflect.KClass

const val UUID_REGEXP = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"

/**
* Validation constraint for {@link UUID}s.
* Reference: https://stackoverflow.com/questions/37320870/is-there-a-uuid-validator-annotation
*/
@Target(AnnotationTarget.FIELD)
@Constraint(validatedBy = [])
@Retention(AnnotationRetention.RUNTIME)
@NotBlank
@Pattern(regexp = UUID_REGEXP)
annotation class UUID(
val message: String = "{invalid.uuid}",
val groups: Array<KClass<*>> = [],
val payload: Array<KClass<out Payload>> = []
)

Written by

Author, CTO. Subscribe to my newsletter: https://mailchi.mp/fb661753d54a/developassion-newsletter. Follow me on Twitter https://twitter.com/dsebastien

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store