How would I create a value object that checks a co...
# announcements
k
How would I create a value object that checks a constructor parameter meets some requirements and has a no arg constructor as well (for JPA)?
Copy code
@Embeddable
data class RouterId(val routerId: String) {

    init {
        val octets = routerId.split(":")

        if (octets.size != 6) {
            throw IllegalArgumentException("$routerId does not consist of 6 octets")
        }

        for (octet in octets) {
            Integer.parseInt(octet, 16)
        }
    }

    private constructor() : this("11:11:11:11:11:11")
}
I think my default value in the private constructor is not so nice 😕