Gavin Ray
09/16/2022, 9:30 PMString
using Jackson
Currently, these are modeled like this:
data class ColumnName
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
constructor(@JsonValue val value: String) {
init {
require(value.isNotBlank()) { "Column name cannot be blank" }
require(value.all { it.isLetterOrDigit() || it == '_' }) { "Column name must be alphanumeric" }
}
}
Would the best practice using your library be to just replace the require()
with require(parse(value))
?Gavin Ray
09/16/2022, 9:41 PMdata class ColumnName
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
constructor(@JsonValue val value: String) {
init {
parser.parse(value).tapInvalid { error(it) }
}
companion object {
val parser = Parser.fromNullableString()
.notNullOrBlank { "Column name cannot be blank" }
.filter({ it.all { it.isLetterOrDigit() || it == '_' } }, { "Column name must be alphanumeric" })
.map { it }
}
}
sam
09/18/2022, 6:55 PMGavin Ray
09/19/2022, 3:16 PM