user9883549
user9883549

Reputation:

How to check if UUID is null, empty or blank?

I have a Springboot application and my entity have a field id and ownerId which is type of UUID. How can i check if the UUID is actually a UUID and not a string or anything else?

My example code:

when {
            project.id != null -> handleIllegalParameter("id")
            project.ownerId != null -> handleIllegalParameter("ownerId")
            project.name.isNullOrBlank() -> handleMissingRequiredField("name")

        }

How can I can check that is actually a UUID and not a string, integer or anything else except UUID?

Upvotes: 1

Views: 16751

Answers (1)

David Soroko
David Soroko

Reputation: 9096

If your id and ownerId are of type UUID? then once you check they are not null - you are good. If they of type String (as the title of your question implies) you can use the UUID.fromString() method that throws IllegalArgumentException if the conversion fails.

Upvotes: 3

Related Questions